﻿namespace BEGDC.CC.Web.UserControls.CR
{
	using System;
	using System.Data;
	using System.Collections;
	using System.Drawing;
	using System.Web;
	using System.Text;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;

	using BEGDC.CC.BL.CCFlow.CV;
	using BEGDC.CC.BL.CCFlow.CR;
	using BEGDC.CC.Entity;
	using BEGDC.CC.BL.Workflow;
	using BEGDC.CC.BL.Common;
	using BEGDC.CC.BL.Common.Query;
	using BEGDC.Utility.Castle;
	using BEGDC.CC.BL.UserManagement;

	/// <summary>
	///	Summary description for Apply.
	/// </summary>
	public class EZCtrl : BaseCR
	{
		#region ui control definition
		protected System.Web.UI.WebControls.Label Lb_CISWarning;
		protected System.Web.UI.WebControls.TextBox Ctl_TravelAgency;
		protected System.Web.UI.WebControls.Label Lb_TravelAgency;
		protected System.Web.UI.WebControls.Label lbDepartmentReadOnly;
		protected System.Web.UI.WebControls.TextBox tbSomeoneName;
		protected System.Web.UI.WebControls.TextBox tbSomeoneEmail;
		protected System.Web.UI.WebControls.TextBox tbCustomerName;
		protected System.Web.UI.WebControls.RadioButtonList rbIsFCPA;
		protected System.Web.UI.WebControls.TextBox tbCustomerCountry;
		protected System.Web.UI.WebControls.RadioButtonList rbReviewGuideLine;
		protected System.Web.UI.WebControls.TextBox tbOtherLocation;
		protected System.Web.UI.WebControls.TextBox tbVisitObjectives;
		protected System.Web.UI.WebControls.CheckBoxList cblPreferredLocation;
		protected System.Web.UI.WebControls.TextBox tbPotentialRevenue;
		protected System.Web.UI.WebControls.DropDownList ddlPotentialRevenueTime;
		protected System.Web.UI.WebControls.DropDownList ddlSaleStage;
		protected System.Web.UI.WebControls.RadioButtonList rbOutStandingRFP;
		protected System.Web.UI.WebControls.TextBox tbSensitiveIssues;
		protected System.Web.UI.WebControls.TextBox tbKeyMessage;
		protected System.Web.UI.WebControls.TextBox tbCompanyProfile;
		protected System.Web.UI.WebControls.DropDownList ddlAccountType;
		protected System.Web.UI.WebControls.TextBox tbProposalNo;
		protected System.Web.UI.WebControls.RadioButtonList rbSalesContract;
		protected System.Web.UI.WebControls.RadioButtonList rbSalesContractSigned;
		protected System.Web.UI.WebControls.TextBox tbNotSalesContractDescription;
		protected System.Web.UI.WebControls.RadioButtonList rbActivityInTrip;
		protected System.Web.UI.WebControls.TextBox tbRequestedDateFrom;
		protected System.Web.UI.WebControls.TextBox tbRequestedDateTo;
		protected System.Web.UI.WebControls.TextBox tbCustomerTeamHost;
		protected System.Web.UI.WebControls.TextBox tbCustomerOfficeTel;
		protected System.Web.UI.WebControls.TextBox tbCustomerFax;
		protected System.Web.UI.WebControls.TextBox tbCustomerEmail;
		protected System.Web.UI.WebControls.DropDownList ddlSalesBusinessUnit;
		protected System.Web.UI.WebControls.DropDownList ddlRegion;
		protected System.Web.UI.WebControls.TextBox tbDatesRequiredFrom;
		protected System.Web.UI.WebControls.TextBox tbDatesRequiredTo;
		protected System.Web.UI.WebControls.TextBox tbPreferEntertainment;
		protected System.Web.UI.WebControls.TextBox tbEntertainmentPriceRangeFrom;
		protected System.Web.UI.WebControls.TextBox tbEntertainmentPriceRangeTo;
		protected System.Web.UI.WebControls.RadioButtonList rbGiftNeed;
		protected System.Web.UI.WebControls.TextBox tbGiftPriceRangeFrom;
		protected System.Web.UI.WebControls.TextBox tbGiftPriceRangeTo;
		protected System.Web.UI.WebControls.RadioButtonList rbReceivedGift;
		protected System.Web.UI.WebControls.TextBox tbNotDirectReason;
		protected System.Web.UI.WebControls.TextBox tbEstimateCostPerPerson;
		protected System.Web.UI.WebControls.RadioButtonList rbCateringService;
		protected System.Web.UI.WebControls.RadioButtonList RBL_KeyMessage;
		protected System.Web.UI.WebControls.TextBox tbCaterServiceExplain;
		protected System.Web.UI.WebControls.TextBox tbPreferGift;
		protected System.Web.UI.WebControls.TextBox tbEstimateTotalCost;
		protected System.Web.UI.WebControls.TextBox tbRequestorName;
		protected System.Web.UI.WebControls.TextBox tbRequestOfficeTel;
		protected System.Web.UI.WebControls.TextBox tbRequestorMobile;
		protected System.Web.UI.WebControls.TextBox tbSomeoneTel;
		protected System.Web.UI.WebControls.RadioButtonList rbEntertainmentNeed;
		protected System.Web.UI.WebControls.Literal litScript;
		protected System.Web.UI.WebControls.Label lbRequestorNameReadOnly;
		protected System.Web.UI.WebControls.Label lbRequestOfficeTelReadOnly;
		protected System.Web.UI.WebControls.Label lbRequestorMobileReadOnly;
		protected System.Web.UI.WebControls.Label lbSomeoneElseReadOnly;
		protected System.Web.UI.WebControls.Label lbSomeoneNameReadOnly;
		protected System.Web.UI.WebControls.Label lbSomeoneTelReadOnly;
		protected System.Web.UI.WebControls.Label lbSomeoneEmailReadOnly;
		protected System.Web.UI.WebControls.Label lbCustomerNameReadOnly;
		protected System.Web.UI.WebControls.Label lbIsFCPAReadOnly;
		protected System.Web.UI.WebControls.Label lbCustomerCountryReadOnly;
		protected System.Web.UI.WebControls.Label lbReviewGuideLineReadOnly;
		protected System.Web.UI.WebControls.Label lbPreferredLocationReadOnly;
		protected System.Web.UI.WebControls.Label lbOtherLocationReadOnly;
		protected System.Web.UI.WebControls.Label lbOtherCountryReadOnly;
		protected System.Web.UI.WebControls.Label lbGuestNumberReadOnly;
		protected System.Web.UI.WebControls.Label lbVisitObjectivesReadOnly;
		protected System.Web.UI.WebControls.Label lbPotentialRevenueReadOnly;
		protected System.Web.UI.WebControls.Label lbPotentialRevenueTimeReadOnly;
		protected System.Web.UI.WebControls.Label lbSaleStageReadOnly;
		protected System.Web.UI.WebControls.Label lbOutStandingRFPReadOnly;
		protected System.Web.UI.WebControls.Label lbSeneitiveIssuesReadOnly;
		protected System.Web.UI.WebControls.Label lbKeyMessageReadOnly;
		protected System.Web.UI.WebControls.Label lbCompanyProfileReadOnly;
		protected System.Web.UI.WebControls.Label lbAccountTypeReadOnly;
		protected System.Web.UI.WebControls.Label lbProposalNoReadOnly;
		protected System.Web.UI.WebControls.Label lbSalesContractReadOnly;
		protected System.Web.UI.WebControls.Label lbSalesContractSignedReadOnly;
		protected System.Web.UI.WebControls.Label lbNotSalesContractDescriptionReadOnly;
		protected System.Web.UI.WebControls.Label lbActivityInTripReadOnly;
		protected System.Web.UI.WebControls.Label lbRequestedDateFromReadOnly;
		protected System.Web.UI.WebControls.Label lbRequestedDateToReadOnly;
		protected System.Web.UI.WebControls.Label lbCustomerTeamHostReadOnly;
		protected System.Web.UI.WebControls.Label lbCustomerOfficeTelReadOnly;
		protected System.Web.UI.WebControls.Label lbCustomerFaxReadOnly;
		protected System.Web.UI.WebControls.Label lbCustomerEmailReadOnly;
		protected System.Web.UI.WebControls.Label lbSalesBusinessUnitReadOnly;
		protected System.Web.UI.WebControls.Label lbRegionReadOnly;
		protected System.Web.UI.WebControls.Label lbDatesRequiredFromReadOnly;
		protected System.Web.UI.WebControls.Label lbDatesRequiredToReadOnly;
		protected System.Web.UI.WebControls.Label lbEntertainmentNeedReadOnly;
		protected System.Web.UI.WebControls.Label lbPreferEntertainmentReadOnly;
		protected System.Web.UI.WebControls.Label lbEntertainmentPriceRangeFromReadOnly;
		protected System.Web.UI.WebControls.Label lbEntertainmentPriceRangeToReadOnly;
		protected System.Web.UI.WebControls.Label lbGiftNeedReadOnly;
		protected System.Web.UI.WebControls.Label lbPreferGiftReadOnly;
		protected System.Web.UI.WebControls.Label lbGiftPriceRangeFromReadOnly;
		protected System.Web.UI.WebControls.Label lbGiftPriceRangeToReadOnly;
		protected System.Web.UI.WebControls.Label lbReceivedGiftReadOnly;
		protected System.Web.UI.WebControls.Label lbNotDirectReasonReadOnly;
		protected System.Web.UI.WebControls.Label lbEstimateTotalCostReadOnly;
		protected System.Web.UI.WebControls.Label lbEstimateCostPerPersonReadOnly;
		protected System.Web.UI.WebControls.Label lbCateringServiceReadOnly;
		protected System.Web.UI.WebControls.Label lbCaterServiceExplainReadOnly;
		protected System.Web.UI.HtmlControls.HtmlImage CustomerPaneImg;
		protected System.Web.UI.HtmlControls.HtmlImage ALPaneImg;
		protected System.Web.UI.HtmlControls.HtmlImage CostCenterPaneImg;
		protected System.Web.UI.HtmlControls.HtmlTableRow tr_Title;
		protected System.Web.UI.HtmlControls.HtmlTableRow tr_Button;
		protected System.Web.UI.HtmlControls.HtmlImage ContractDateImg;
		protected System.Web.UI.WebControls.RadioButtonList rbSomeoneElse;
		protected System.Web.UI.HtmlControls.HtmlGenericControl RequestedDateFromSpan;
		protected System.Web.UI.HtmlControls.HtmlGenericControl tbRequestedDateToSpan;
        protected System.Web.UI.HtmlControls.HtmlGenericControl tbRequestedDateFromSpan;
		protected System.Web.UI.HtmlControls.HtmlGenericControl tbDatesRequiredFromSpan;
		protected System.Web.UI.HtmlControls.HtmlGenericControl tbDatesRequiredToSpan;
		protected System.Web.UI.WebControls.DropDownList Dp_Department;
		protected System.Web.UI.WebControls.DataGrid dgContractInfo;
		protected System.Web.UI.HtmlControls.HtmlImage ConrtractInfoPane;
		protected System.Web.UI.WebControls.Label tx_AllDepts;
		protected System.Web.UI.WebControls.Label tx_Account;
		protected BEGDC.CC.Web.Control.UserSearchControl SearchStaff;
		protected System.Web.UI.HtmlControls.HtmlTable Table_Contract;
		protected System.Web.UI.HtmlControls.HtmlTableRow TR_Catering;
		protected System.Web.UI.WebControls.DataGrid dgCustomerList;
		protected System.Web.UI.WebControls.DataGrid dgALAttendee;
		protected System.Web.UI.WebControls.DataGrid dgCostCenter;
		protected System.Web.UI.HtmlControls.HtmlImage HotelBookingImg;
		protected System.Web.UI.HtmlControls.HtmlImage CompanyCarImg;
		protected System.Web.UI.HtmlControls.HtmlImage LeaseCarImg;
		protected System.Web.UI.WebControls.Label Lb_RFPDetails;
		protected System.Web.UI.WebControls.TextBox Ctl_RFPDetails;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.RadioButtonList RB_IsSensitiveIssue;
		protected System.Web.UI.WebControls.TextBox Ctl_DetailedItinerary;
		protected System.Web.UI.WebControls.Label Lb_DetailedItinerary;
		protected System.Web.UI.WebControls.TextBox tbTopic;
		protected System.Web.UI.WebControls.Label lbTopicReadOnly;
		protected System.Web.UI.WebControls.Label tx_MeetingRoom;
		protected System.Web.UI.WebControls.RadioButtonList RBL_Meal;

		protected System.Web.UI.WebControls.TextBox Ctl_HotelComment;
		protected System.Web.UI.WebControls.TextBox Ctl_MealContent;

		protected System.Web.UI.WebControls.Label lbhotelcomment;
		protected System.Web.UI.WebControls.Label tx_MealContent;
		protected System.Web.UI.WebControls.TextBox Ctl_MealEachCost;
		protected System.Web.UI.WebControls.Label LB_MealEachCost;
		protected System.Web.UI.WebControls.TextBox Ctl_ArrivalFlightNo;
		protected System.Web.UI.WebControls.Label tx_ArrivalFightNo;
		protected System.Web.UI.WebControls.TextBox Ctl_ArrivalAirport;
		protected System.Web.UI.WebControls.Label tx_ArrivalAirport;
		protected System.Web.UI.WebControls.TextBox ArrivalTime;
		protected System.Web.UI.WebControls.Label tx_ArrivalTime;
		protected System.Web.UI.WebControls.TextBox Ctl_LeaveFlightNo;
		protected System.Web.UI.WebControls.Label tx_LeaveFightNo;
		protected System.Web.UI.WebControls.TextBox Ctl_LeaveAirport;
		protected System.Web.UI.WebControls.Label tx_LeaveAirport;
		protected System.Web.UI.WebControls.TextBox LeaveTime;
		protected System.Web.UI.WebControls.Label tx_LeaveTime;
		protected System.Web.UI.HtmlControls.HtmlGenericControl ArrivalTimeSpan;
		protected System.Web.UI.HtmlControls.HtmlGenericControl LeaveTimeSpan;
		protected System.Web.UI.WebControls.TextBox Ctl_GiftsDetails;
		protected System.Web.UI.WebControls.Label Lb_GiftDetails;
		protected System.Web.UI.WebControls.RadioButtonList RB_IsTravelAgency;
		protected System.Web.UI.WebControls.Label Lb_IsTravelAgency;
		protected System.Web.UI.WebControls.RadioButtonList RBL_message;
		protected System.Web.UI.HtmlControls.HtmlTableRow MealReservationPane;
		protected System.Web.UI.WebControls.TextBox Ctl_HRID;
		protected System.Web.UI.WebControls.Label LB_HRID;
		protected System.Web.UI.WebControls.TextBox Ctl_SomeoneMobil;
		protected System.Web.UI.WebControls.Label Lb_SomeoneMobil;
		protected System.Web.UI.WebControls.Label lbIsSensitiveIssue;
		protected System.Web.UI.WebControls.Label lbKeyMessage;
		protected System.Web.UI.WebControls.Label Lb_IsMealReservation;
		protected System.Web.UI.WebControls.DropDownList Dp_MeetingRoom;
		protected System.Web.UI.WebControls.DropDownList Dp_Account;
		protected System.Web.UI.HtmlControls.HtmlTableRow TR_Account;
		protected System.Web.UI.WebControls.Label lbContractSum;
		protected System.Web.UI.WebControls.Label lbCostSum;
		protected System.Web.UI.WebControls.DataGrid dgHotel;
		protected System.Web.UI.WebControls.DataGrid dgCompanyCar;
		protected System.Web.UI.WebControls.DataGrid dgLeaseCar;
		protected System.Web.UI.WebControls.Label lbEZVisitNoReadOnly;
		protected System.Web.UI.WebControls.Label lbLGDNoReadOnly;
		protected System.Web.UI.HtmlControls.HtmlTableRow TR_ID;
		protected System.Web.UI.WebControls.DropDownList ddlLegalEntity;
		protected System.Web.UI.WebControls.Label lblLegalEntity;
		protected System.Web.UI.WebControls.Label lbSummaryReadOnly;
		protected System.Web.UI.HtmlControls.HtmlTableRow TR_Knowledge;
		protected System.Web.UI.HtmlControls.HtmlTableRow TR_KnowledgeTitle;
		private bool _isReadOnly = false;
		protected System.Web.UI.WebControls.TextBox Ctl_LogisticComment;
		protected System.Web.UI.WebControls.Label lbLogisticComment;
		protected System.Web.UI.WebControls.Label lbExpenseTypeReadOnly;
		protected System.Web.UI.WebControls.DropDownList Dp_ExpenseType;
		protected System.Web.UI.WebControls.TextBox HiddenGiftAttachment;
		protected System.Web.UI.WebControls.Image ItemImage1;
		protected System.Web.UI.WebControls.Image ItemImage2;
		protected System.Web.UI.WebControls.Image ItemImage3;
		protected System.Web.UI.WebControls.Image ItemImage4;
		protected System.Web.UI.WebControls.Image ItemImage5;
		protected System.Web.UI.WebControls.Image ItemImage6;
		protected System.Web.UI.WebControls.Image ItemImage7;
		protected System.Web.UI.WebControls.Image ItemImage8;
		protected System.Web.UI.WebControls.Image ItemImage9;
		protected System.Web.UI.WebControls.Image ItemImage10;
		protected System.Web.UI.WebControls.Image ItemImage11;
		protected System.Web.UI.WebControls.Image ItemImage12;
		protected System.Web.UI.WebControls.Image ItemImage13;
		protected System.Web.UI.WebControls.Image ItemImage14;
		protected System.Web.UI.WebControls.Image ItemImage15;

		private bool _isKnowledgeVisible = false;
		#endregion

		#region Properties
		public bool KnowledgeVisible
		{
			set
			{
				_isKnowledgeVisible = value;
			}
			get
			{
				return _isKnowledgeVisible;
			}
		}
		public string RequestDateFrom
		{
			get
			{
				return this.tbRequestedDateFrom.Text;
			}
		}
		public string RequestDateTo
		{
			get
			{
				return this.tbRequestedDateTo.Text;
			}
		}
		protected DateTime RequestDate
		{
			get
			{ 
				if( this.ViewState["RequestDate"] == null )
					return System.DateTime.Now;
				return (DateTime)this.ViewState["RequestDate"]; 
			}
			set{ this.ViewState["RequestDate"] = value; }
		}
		public bool isReadOnly
		{
			set
			{
				_isReadOnly = value;
			}
			get
			{
				return _isReadOnly;
			}
		}
		public bool isNeedGift
		{
			get
			{
				return this.rbGiftNeed.SelectedValue == "1";
			}
		}
		public bool isNeedContract
		{
			get
			{
				return this.rbSalesContract.SelectedValue == "1";
			}
		}
		public int CustomerID
		{
			set
			{
				ViewState["customerID"] = value;
			}
			get
			{
				if(ViewState["customerID"] == null)
					return 0;
				return Convert.ToInt32(ViewState["customerID"]);
			}
		}
		public int BusinessID
		{
			set
			{
				ViewState["businessID"] = value;
			}
			get
			{
				if(ViewState["businessID"] == null)
					return 0;
				return Convert.ToInt32(ViewState["businessID"]);
			}
		}
		public int TopicID
		{
			set
			{
				ViewState["topicID"] = value;
			}
			get
			{
				if(ViewState["topicID"] == null)
					return 0;
				return Convert.ToInt32(ViewState["topicID"]);
			}
		}
		public int SalesTeamID
		{
			set
			{
				ViewState["salesTeamID"] = value;
			}
			get
			{
				if(ViewState["salesTeamID"] == null)
					return 0;
				return Convert.ToInt32(ViewState["salesTeamID"]);
			}
		}
		public int LogistID
		{
			set
			{
				ViewState["logistID"] = value;
			}
			get
			{
				if(ViewState["logistID"] == null)
					return 0;
				return Convert.ToInt32(ViewState["logistID"]);
			}
		}
		public int PaymentID
		{
			set
			{
				ViewState["paymentID"] = value;
			}
			get
			{
				if(ViewState["paymentID"] == null)
					return 0;
				return Convert.ToInt32(ViewState["paymentID"]);
			}
		}

		public string Dp_Dept_Value
		{
			get
			{
				return this.Dp_Department.SelectedItem.Value.ToString();
			}
		}
		public string Dp_CAT_Value
		{
			get
			{
				return this.Dp_Account.SelectedItem.Value.ToString();
			}
		}
		protected string ApplicationNo
		{
			get
			{ 
				if( this.ViewState["ApplicationNo"] == null )
					return string.Empty;
				return this.ViewState["ApplicationNo"].ToString(); 
			}
			set{ this.ViewState["ApplicationNo"] = value; }
		}
		private bool IsView
		{
			get
			{
				string state = this.Request.QueryString["State"];
				if(state == null) return false;
				if(state == SysDicItem.ProjectStatusFlag.QUERY || state == SysDicItem.ProjectStatusFlag.View
					|| state == SysDicItem.ProjectStatusFlag.Pending || state == SysDicItem.ProjectStatusFlag.End)
					return true;
				else
					return false;
			}
		}
		protected string Step
		{
			get
			{
				IQuery queryService = BEGDC.Utility.Castle.AppContainer.Instance[BEGDC.CC.BL.Common.ServiceConst.QueryService] as IQuery;
				FlowInstance flowInstance = queryService.QueryFlowInstance( this.AppID );
				if( flowInstance == null )
					return "Close";
				else
					return flowInstance.CurrentActiveStep.StepCode;
			}
		}

		public int CustomerNum
		{
			get
			{
				if(this.dgCustomerList!=null)
					return this.dgCustomerList.Items.Count;
				else
					return 0;
			}
		}

		public int AccompanyNum
		{
			get
			{
				if(this.dgALAttendee!=null)
					return this.dgALAttendee.Items.Count;
				else
					return 0;
			}
		}

		public int HotelNum
		{
			get
			{
				if(this.dgHotel!=null)
					return this.dgHotel.Items.Count;
				else
					return 0;
			}
		}

		public int CostCenterNum
		{
			get
			{
				if(this.dgCostCenter!=null)
					return this.dgCostCenter.Items.Count;
				else
					return 0;
			}
		}

		public bool IsSomeoneElse
		{
			get
			{
				if(this.rbSomeoneElse.SelectedValue=="1")
				{
					return true;
				}
				else
				{
					return false;
				}
			}
		}

		public BEGDC.CC.Entity.Employee SomeoneEmployee
		{
			get
			{
				if(this.SearchStaff.EmployeeID!="")
				{
					return this.GetUserById(this.SearchStaff.EmployeeID);
				}
				else
				{
					return null;
				}
			}
		}
		#endregion

		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			if(!Page.IsPostBack)
			{
                if (!this.Application.IsTransition) return;
				this.TR_Knowledge.Visible = false;
				this.TR_KnowledgeTitle.Visible  =false;

				//base.PreInitForm();
				InitialDropDownList();
				BindApplication();

				#region ItemImage
				ItemImage1.ImageUrl = WebUtility.Path + "\\images\\item.gif";
				ItemImage2.ImageUrl = WebUtility.Path + "\\images\\item.gif";
				ItemImage3.ImageUrl = WebUtility.Path + "\\images\\item.gif";
				ItemImage4.ImageUrl = WebUtility.Path + "\\images\\item.gif";
				ItemImage5.ImageUrl = WebUtility.Path + "\\images\\item.gif";
				ItemImage6.ImageUrl = WebUtility.Path + "\\images\\item.gif";
				ItemImage7.ImageUrl = WebUtility.Path + "\\images\\item.gif";
				ItemImage8.ImageUrl = WebUtility.Path + "\\images\\item.gif";
				ItemImage9.ImageUrl = WebUtility.Path + "\\images\\item.gif";
				ItemImage10.ImageUrl = WebUtility.Path + "\\images\\item.gif";
				ItemImage11.ImageUrl = WebUtility.Path + "\\images\\item.gif";
				ItemImage12.ImageUrl = WebUtility.Path + "\\images\\item.gif";
				ItemImage13.ImageUrl = WebUtility.Path + "\\images\\item.gif";
				ItemImage14.ImageUrl = WebUtility.Path + "\\images\\item.gif";
				ItemImage15.ImageUrl = WebUtility.Path + "\\images\\item.gif";
				#endregion

				//this.SearchStaff.SelfID = ((BEGDC.CC.BL.Workflow.CCIdentity)Page.User.Identity).UserInfo.Id;

				#region Radio List OnClick

            
                //this.rbSomeoneElse.Attributes["onclick"] = "javascript:ShowSomeOneElsePane();";
                //this.rbOutStandingRFP.Attributes["onclick"] = "javascript:ShowRFPDetailPane();";
                //this.RB_IsSensitiveIssue.Attributes["onclick"] = "javascript:ShowSensitiveIssuePane();";
                //this.RBL_KeyMessage.Attributes["onclick"] = "javascript:ShowKeyMessageDetailPane();";

                //this.rbSalesContract.Attributes["onclick"] = "javascript:ShowSalesContractPane();";
                //this.rbSalesContractSigned.Attributes["onclick"] = "javascript:ShowSalesContractSignedPane();";
                //this.rbActivityInTrip.Attributes["onclick"] = "javascript:ShowActivityInTripPane();";

                //this.RBL_Meal.Attributes["onclick"] = "javascript:ShowRBL_MealPane();";
                //this.rbEntertainmentNeed.Attributes["onclick"] = "javascript:ShowEntertainmentNeedPane();";
                //this.rbGiftNeed.Attributes["onclick"] = "javascript:ShowGiftNeedPane();";
                //this.rbReceivedGift.Attributes["onclick"] = "javascript:ShowReceivedGiftPane();";
                //this.RB_IsTravelAgency.Attributes["onclick"] = "javascript:ShowTravelAgencyPane();";
                //this.rbCateringService.Attributes["onclick"] = "javascript:ShowCateringServicePane();";
				#endregion
			}
			else
			{
				#region RELOAD DATAGRID
				BindCustomerAttendee();
				BindALAttendee();
				BindCostCenter();
				BindContractInfo();
				DataTable HotelDataTable = null;
				object SessHotelBooking = Session[SessionFlag.HotelSessionEZ];
				if(SessHotelBooking!=null)
				{
					HotelDataTable = (DataTable)SessHotelBooking;
					this.dgHotel.DataSource = HotelDataTable;
					this.dgHotel.DataBind();
				}
				DataTable CompanyCarDataTable = null;
				object SessCompanyCarBooking = Session[SessionFlag.CompanyCarSessionEZ];
				if(SessCompanyCarBooking!=null)
				{
					CompanyCarDataTable = (DataTable)SessCompanyCarBooking;
					this.dgCompanyCar.DataSource = CompanyCarDataTable;
					this.dgCompanyCar.DataBind();
					//this.Lb_TotalPriceForCompanyCar.Text = CaculateTotalPriceForLeaseCar(CompanyCarDataTable);
				}
				DataTable LeaseCarDataTable = null;
				object SessLeaseCarBooking = Session[SessionFlag.LeaseCarSessionEZ];
				if(SessLeaseCarBooking!=null)
				{
					LeaseCarDataTable = (DataTable)SessLeaseCarBooking;
					this.dgLeaseCar.DataSource = LeaseCarDataTable;
					this.dgLeaseCar.DataBind();
					//this.Lb_TotalPriceForLeaseCar.Text = CaculateTotalPriceForLeaseCar(LeaseCarDataTable);
				}
				#endregion
			}
//			Page.SmartNavigation = true;
			//ShowBlock();
		}

		#region RegisterClientScripts
//		public void RegisterClientScripts()
//		{
//			StringBuilder sb = new StringBuilder();
//			if(Page.IsPostBack)
//			{
//				//Post back get init value from control.
//				sb.Append("<script language=\"javascript\">\n");
//				sb.Append("var _SomeoneElse;\n");
//				sb.Append("var _RFPDetail;\n");
//				sb.Append("var _SensitiveIssue;\n");
//				sb.Append("var _KeyMessageDetail;\n");
//				sb.Append("var _SalesContract;\n");
//				sb.Append("var _SalesContractSigned;\n");
//				sb.Append("var _ActivityInTrip;\n");
//				sb.Append("var _EntertainmentNeed;\n");
//				sb.Append("var _GiftNeed;\n");
//				sb.Append("var _ReceivedGift;\n");
//				sb.Append("var _TravelAgency;\n");
//				sb.Append("var _CateringService;\n");
//				if(this.Application == null)
//				{
//					sb.Append("_SomeoneElse = false;\n");
//				}
//				else
//				{
//					sb.Append("_SomeoneElse = ");
//					sb.Append(this.Application.ApplyForSomeoneElse ? "true":"false");
//					sb.Append(";\n");
//				}
//
//				sb.Append("_RFPDetail = ");
//				sb.Append(this.rbOutStandingRFP.SelectedValue == "1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("_SensitiveIssue = ");
//				sb.Append(this.RB_IsSensitiveIssue.SelectedValue == "1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("_KeyMessageDetail = ");
//				sb.Append(this.RBL_KeyMessage.SelectedValue =="1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("_SalesContract = ");
//				sb.Append(this.rbSalesContract.SelectedValue == "1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("_SalesContractSigned = ");
//				sb.Append(this.rbSalesContractSigned.SelectedValue =="1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("_ActivityInTrip = ");
//				sb.Append(this.rbActivityInTrip.SelectedValue =="1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("_EntertainmentNeed = ");
//				sb.Append(this.rbEntertainmentNeed.SelectedValue =="1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("_GiftNeed = ");
//				sb.Append(this.rbGiftNeed.SelectedValue=="1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("_ReceivedGift = ");
//				sb.Append(this.rbReceivedGift.SelectedValue=="1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("_TravelAgency = ");
//				sb.Append(this.RB_IsTravelAgency.SelectedValue == "1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("_CateringService = ");
//				sb.Append(this.rbCateringService.SelectedValue == "1" ? "true":"false");
//				sb.Append(";\n");
//				sb.Append("</script>");
//			}
//			else
//			{
//				sb.Append("<script language=\"javascript\">\n");
//				sb.Append("var _SomeoneElse;\n");
//				sb.Append("var _RFPDetail;\n");
//				sb.Append("var _SensitiveIssue;\n");
//				sb.Append("var _KeyMessageDetail;\n");
//				sb.Append("var _SalesContract;\n");
//				sb.Append("var _SalesContractSigned;\n");
//				sb.Append("var _ActivityInTrip;\n");
//				sb.Append("var _EntertainmentNeed;\n");
//				sb.Append("var _GiftNeed;\n");
//				sb.Append("var _ReceivedGift;\n");
//				sb.Append("var _TravelAgency;\n");
//				sb.Append("var _CateringService;\n");
//
//				if(this.Application == null) 
//				{
//					sb.Append("_SomeoneElse = false;\n");
//				}
//				else
//				{
//					sb.Append("_SomeoneElse = ");
//					sb.Append(this.Application.ApplyForSomeoneElse ? "true":"false");
//					sb.Append(";\n");
//				}
//
//				sb.Append("_RFPDetail = ");
//				sb.Append(m_CachedCustomer==null? "false":(m_CachedCustomer.IsInRFP ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("_SensitiveIssue = ");
//				sb.Append(m_CachedCustomer==null? "false":(m_CachedCustomer.IsSensitiveIssue ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("_KeyMessageDetail = ");
//				sb.Append(m_CachedCustomer==null? "false":(m_CachedCustomer.IsKeyMessage ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("_SalesContract = ");
//				sb.Append(m_CachedBusiness==null? "false":(m_CachedBusiness.IsInSalesContract ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("_SalesContractSigned = ");
//				sb.Append(m_CachedBusiness==null? "false":(m_CachedBusiness.IsContractSigned ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("_ActivityInTrip = ");
//				sb.Append(m_CachedBusiness==null? "false":(m_CachedBusiness.RecreationalActivity ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("_EntertainmentNeed = ");
//				sb.Append(m_CachedLogist==null? "false":(m_CachedLogist.IsNeedEntertainment ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("_GiftNeed = ");
//				sb.Append(m_CachedLogist==null? "false":(m_CachedLogist.IsNeedGift ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("_ReceivedGift = ");
//				sb.Append(m_CachedLogist==null? "false":(m_CachedLogist.IsReceivedALGiftBefore ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("_TravelAgency = ");
//				sb.Append(m_CachedLogist==null? "false":(m_CachedLogist.IsNeedTravelAgency ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("_CateringService = ");
//				sb.Append(m_CachedLogist==null? "false":(m_CachedLogist.IsNeedCatering ? "true":"false"));
//				sb.Append(";\n");
//				sb.Append("</script>");
//				
//			}
//
//			if(!Page.IsClientScriptBlockRegistered("EZCtrlForCO"))
//			{
//				Page.RegisterClientScriptBlock("EZCtrlForCO",sb.ToString());
//			}
//			sb = new StringBuilder();
//			if(!Page.IsStartupScriptRegistered("EZCtrlForCO_Startup"))
//			{
//				sb.Append( "<script language=\"javascript\">\n");
//				sb.Append( "DisplaySomeOneElsePane(_SomeoneElse);\n");
//				sb.Append( "DisplayRFPDetailPane(_RFPDetail);\n");
//				sb.Append( "DisplaySensitiveIssuePane(_SensitiveIssue);\n");
//				sb.Append( "DisplayKeyMessageDetailPane(_KeyMessageDetail);\n");
//				sb.Append( "DisplaySalesContractPane(_SalesContract);\n");
//				sb.Append( "DisplaySalesContractSignedPane(_SalesContractSigned);\n");
//				sb.Append( "DisplayActivityInTripPane(_ActivityInTrip);\n");
//				sb.Append( "DisplayRBL_MealPane(_RBL_Meal);\n");
//				sb.Append( "DisplayEntertainmentNeedPane(_EntertainmentNeed);\n");
//				sb.Append( "DisplayGiftNeedPane(_GiftNeed);\n");
//				sb.Append( "DisplayReceivedGiftPane(_ReceivedGift);\n");
//				sb.Append( "DisplayTravelAgencyPane(_TravelAgency);\n");
//				sb.Append( "DisplayCateringServicePane(_CateringService);\n");
//				sb.Append("</script>\n");
//
//				Page.RegisterStartupScript("EZCtrlForCO_Startup",sb.ToString());
//			}
//		}
		#endregion

		#region ShowBlock
		private void ShowBlock()
		{
			StringBuilder sb = new StringBuilder();
			if(!Page.IsStartupScriptRegistered("EZCtrl_Startup"))
			{
				sb.Append( "<script language=\"javascript\">\n");
				if(this.isReadOnly)
				{
					sb.Append( "DisplaySomeOneElsePane("+this.rbSomeoneElse.SelectedValue+");\n");
					sb.Append( "DisplayRFPDetailPane("+this.rbOutStandingRFP.SelectedValue+");\n");
					sb.Append( "DisplaySensitiveIssuePane("+this.RB_IsSensitiveIssue.SelectedValue+");\n");
					sb.Append( "DisplayKeyMessageDetailPane("+this.RBL_KeyMessage.SelectedValue+");\n");
					sb.Append( "DisplayEntertainmentNeedPane("+this.rbEntertainmentNeed.SelectedValue+");\n");
					sb.Append( "DisplayGiftNeedPane("+this.rbGiftNeed.SelectedValue+");\n");
					sb.Append( "DisplayReceivedGiftPane("+this.rbReceivedGift.SelectedValue+");\n");
					sb.Append( "DisplayActivityInTripPane("+this.rbActivityInTrip.SelectedValue+");\n");
					sb.Append( "DisplayRBL_MealPane("+this.RBL_Meal.SelectedValue+");\n");
					sb.Append( "DisplayTravelAgencyPane("+this.RB_IsTravelAgency.SelectedValue+");\n");
					sb.Append( "DisplaySalesContractPane("+this.rbSalesContract.SelectedValue+");\n");
					sb.Append( "DisplaySalesContractSignedPane("+this.rbSalesContractSigned.SelectedValue+");\n");
					sb.Append( "DisplayCateringServicePane("+this.rbCateringService.SelectedValue+");\n");
				}
				else
				{
					sb.Append( "ShowSomeOneElsePane();\n");
					sb.Append( "ShowRFPDetailPane();\n");
					sb.Append( "ShowSensitiveIssuePane();\n");
					sb.Append( "ShowKeyMessageDetailPane();\n");
					sb.Append( "ShowEntertainmentNeedPane();\n");
					sb.Append( "ShowGiftNeedPane();\n");
					sb.Append( "ShowReceivedGiftPane();\n");
					sb.Append( "ShowActivityInTripPane();\n");
					sb.Append( "ShowRBL_MealPane();\n");
					sb.Append( "ShowSalesContractPane();\n");
					sb.Append( "ShowTravelAgencyPane();\n");
					sb.Append( "ShowSalesContractPane();\n");
					sb.Append( "ShowCateringServicePane();\n");
				}
				sb.Append("</script>\n");

				Page.RegisterStartupScript("EZCtrl_Startup",sb.ToString());
			}
		}
		#endregion

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Dp_Department.SelectedIndexChanged += new System.EventHandler(this.CATBranch_SelectChange);
			this.rbSomeoneElse.SelectedIndexChanged += new System.EventHandler(this.rbSomeoneElse_SelectedIndexChanged);
			this.rbSalesContractSigned.SelectedIndexChanged += new System.EventHandler(this.Contract_Select);
			this.dgContractInfo.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgContractInfo_DeleteCommand);
			this.dgContractInfo.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgContractInfo_ItemDataBound);
			this.dgCustomerList.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgCustomerList_DeleteCommand);
			this.dgCustomerList.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgCustomerList_ItemDataBound);
			this.dgALAttendee.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgALAttendee_DeleteCommand);
			this.dgALAttendee.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgALAttendee_ItemDataBound);
			this.dgHotel.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.EZHotelList_DeleteCommand);
			this.dgHotel.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.EZHotelDataBound);
			this.dgCompanyCar.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.EZCompanyCarDeleteCommand);
			this.dgCompanyCar.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.EZCompanyCarDataBound);
			this.dgLeaseCar.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.EZLeaseCarDeleteCommand);
			this.dgLeaseCar.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.EZLeaseCarDataBound);
			this.dgCostCenter.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgCostCenter_DeleteCommand);
			this.dgCostCenter.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgCostCenter_ItemDataBound);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		#region InitialDropDownList
		private void InitialDropDownList()
		{
			IQuery queryService = BEGDC.Utility.Castle.AppContainer.Instance[BEGDC.CC.BL.Common.ServiceConst.QueryService] as IQuery;

			WebUtility.BuildDropDown(ddlPotentialRevenueTime,BEGDC.CC.BL.Common.DicType.POTENTIAL_REVENUE_TIMEFRAME,false,false);
			WebUtility.BuildDropDown(ddlSaleStage,BEGDC.CC.BL.Common.DicType.SALES_STAGE,false,false);
			WebUtility.BuildDropDown(ddlAccountType,BEGDC.CC.BL.Common.DicType.ACCOUNT_TYPE,false,false);
			WebUtility.BuildDropDown(ddlSalesBusinessUnit,BEGDC.CC.BL.Common.DicType.SALES_BUSINESS_UNIT,false,false);
			WebUtility.BuildDropDown(ddlRegion,BEGDC.CC.BL.Common.DicType.REGION,false,false);
			WebUtility.BuildDropDown(this.Dp_MeetingRoom,BEGDC.CC.BL.Common.DicType.MeetingRoom,false,false);
			WebUtility.BuildDropDown(this.Dp_ExpenseType,BEGDC.CC.BL.Common.DicType.ExpenseType,false,false);

			//WebUtility.BuildDropDown(ddlPayingFor,BEGDC.CC.BL.Common.DicType.PAYER,false,false);
			WebUtility.BuildCheckBoxList(cblPreferredLocation,BEGDC.CC.BL.Common.DicType.ASB_Visiting_Locations);

			BEGDC.CC.BL.Common.IUtility utility = AppContainer.Instance[ServiceConst.UtilityService] as BEGDC.CC.BL.Common.IUtility;
			IList DeptList = utility.BuildDicList(BEGDC.CC.BL.Common.DicType.BRANCH);

			//init legal entity
			this.ddlLegalEntity.DataSource = queryService.GetAllLegalEntity();
			this.ddlLegalEntity.DataTextField = "LegalEntityName";
			this.ddlLegalEntity.DataValueField = "LegalEntityID";
			this.ddlLegalEntity.DataBind();

//			this.ddlCATBranch.DataSource = DeptList;
//			this.ddlCATBranch.DataValueField = "DicItemKey";
//			this.ddlCATBranch.DataTextField = "Description";
//			this.ddlCATBranch.DataBind();
//
//			this.ddlCATBranch.Items.Insert(0,new System.Web.UI.WebControls.ListItem("其他部门","OTH"));
//			this.ddlCATBranch.Items.Insert(0,new System.Web.UI.WebControls.ListItem("总公司","HQ"));
//			
//			IList CATList = utility.GetALLCATList();
//			this.ddlAccount.DataSource = CATList;
//			this.ddlAccount.DataValueField = "DepartmentCode";
//			this.ddlAccount.DataTextField = "DepartmentCode";
//			this.ddlAccount.DataBind();
		}
		#endregion

		#region BindApplication

		private void BuildDepartmentCATList()
		{
			//BEGDC.CC.BL.Common.IUtility utility = AppContainer.Instance[ServiceConst.UtilityService] as BEGDC.CC.BL.Common.IUtility;
			//IList DeptList = utility.BuildDicList(BEGDC.CC.BL.Common.DicType.BRANCH);

			BEGDC.CC.BL.Common.Query.IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as BEGDC.CC.BL.Common.Query.IQuery;
			DataTable catTable = queryService.GetDeptByTypeName( BEGDC.CC.BL.Common.DicType.CAT );
			DataTable branchTable = queryService.GetDeptByTypeName( BEGDC.CC.BL.Common.DicType.BRANCH );

			DataRow[] rows = catTable.Select();
			foreach( DataRow row in rows )
			{
				branchTable.ImportRow(row);
			}

			this.Dp_Department.DataSource = branchTable;
			this.Dp_Department.DataValueField = "DepartmentCode";
			this.Dp_Department.DataTextField = "DepartmentCode";
			this.Dp_Department.DataBind();

			this.Dp_Department.Items.Insert(this.Dp_Department.Items.Count,new System.Web.UI.WebControls.ListItem("Other Department","OTH"));
			//this.Dp_Department.Items.Insert(0,new System.Web.UI.WebControls.ListItem("HQ","HQ"));

			if(this.Dp_Department.Items.Count>0)
			{
				this.Dp_Department.Items[0].Selected = true;
			}

			// Initialize Account Dropdown List

			DataTable accountTable = queryService.GetDicItemByTypeName( BEGDC.CC.BL.Common.DicType.ACCOUNT );
			this.Dp_Account.DataSource = accountTable.DefaultView;
			this.Dp_Account.DataValueField = "DicItemKey";
			this.Dp_Account.DataTextField = "DicItemKey";
			this.Dp_Account.DataBind();

			//			this.Dp_CAT.DataSource = catTable;
			//			this.Dp_CAT.DataValueField = "DepartmentCode";
			//			this.Dp_CAT.DataTextField = "DepartmentCode";
			//			this.Dp_CAT.DataBind();
			if(this.Dp_Account.Items.Count>0)
			{
				this.Dp_Account.Items[0].Selected = true;
			}
		}


		//private CustomerInfo m_CachedCustomer;
		//private BusinessPurpose m_CachedBusiness;
		//private LogisticalInfo m_CachedLogist;

		private void BindApplication()
		{
			this.LoadApplication();

			if(this.Application!=null)
			{
				if(!this.Application.IsTransition) return;
			}

			BuildDepartmentCATList();

			if(this.Application!=null)
			{
				if(this.Application.EZVisitReqNo!=""||this.Application.LGDNo!="")
				{
					this.lbEZVisitNoReadOnly.Text = this.Application.EZVisitReqNo;
					this.lbLGDNoReadOnly.Text = this.Application.LGDNo;
					this.TR_ID.Visible = true;
				}
				else
				{
					this.TR_ID.Visible = false;
				}
				this.Dp_Department.SelectedIndex = Dp_Department.Items.IndexOf(Dp_Department.Items.FindByValue(this.Application.AllDept));
				if(this.Application.Account!=string.Empty)
				{
					this.Dp_Account.SelectedIndex = this.Dp_Account.Items.IndexOf(this.Dp_Account.Items.FindByText(this.Application.Account));
				}
				else
				{
					this.TR_Account.Visible = false;
				}
			}
			else
			{
				this.TR_ID.Visible = false;
			}

			Employee CurrentUser = this.GetUser(HttpContext.Current.User.Identity.Name);

			if(this.AppID == 0)
			{
				BindHotelData(null);
				BindCompanyCarData(null);
				BindLeaseCarData(null);
				BindContractInfo();
				BindCustomerAttendee();
				BindALAttendee();
				BindCostCenter();

				if(CurrentUser!=null)
				{
					this.tbRequestorName.Text = CurrentUser.NameEN;
					//Employee emp = this.GetUser(HttpContext.Current.User.Identity.Name);
					this.lbDepartmentReadOnly.Text = CurrentUser.Department.DepartmentCode;
				}
				return;
			}


			IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
			CustomerInfo customer = queryService.GetCustomerInfo(this.AppID);
			BusinessPurpose business = queryService.GetBusinessPurposeInfo(this.AppID);
			Topic topic = queryService.GetTopicInfo(this.AppID);
			SalesTeamInfo salesTeam = queryService.GetSalesTeamInfo(this.AppID);
			LogisticalInfo logist = queryService.GetLogisticalInfo(this.AppID);
			PaymentInfo payment = queryService.GetPaymentInfo(this.AppID);
			DataTable visitingSite = queryService.GetVisitingSite(this.AppID);

			this.CustomerID = customer.Id;
			this.BusinessID = business.Id;
			this.TopicID = topic.Id;
			this.SalesTeamID = salesTeam.Id;
			this.LogistID = logist.Id;
			this.PaymentID = payment.Id;

			BindApplicationData(visitingSite);
			BindCustomerInfoData(customer);
			BindBusinessPurposeData(business);
			BindTopicData(topic);
			BindSalesTeamData(salesTeam);
			BindLogisticalData(logist);
			BindHotelData(logist);
			BindCompanyCarData(logist);
			BindLeaseCarData(logist);
			BindPaymentData(payment);

			BindCustomerAttendee();
			BindALAttendee();
			BindCostCenter();
			BindContractInfo();

			if(this.isReadOnly)
				BindReadOnlyStatus();
		}

		private Employee GetUser(string name)
		{
			IUser userService = AppContainer.Instance[ServiceConst.UserService] as IUser;
			return userService.GetUser(name);
		}

		private Employee GetUserById(string Id)
		{
			IUser userService = AppContainer.Instance[ServiceConst.UserService] as IUser;
			return userService.GetUserByID(Id);
		}


		private void BindApplicationData(DataTable site)
		{
			this.tbRequestorName.Text = this.Application.RequesterNameEN;
			this.tbRequestOfficeTel.Text = this.Application.RequesterOfficeTel;
			this.tbRequestorMobile.Text = this.Application.RequesterMobile;
			this.rbReviewGuideLine.SelectedValue = this.Application.IsReviewedGuideline? "1":"0";
			this.tbOtherLocation.Text = this.Application.OtherSite;

			if(this.Application.RequestedDateFrom!=null)
			{
				this.tbRequestedDateFrom.Text = ((DateTime)this.Application.RequestedDateFrom).ToString("MM/dd/yyyy");
			}
			if(this.Application.RequestedDateTo!=null)
			{
				this.tbRequestedDateTo.Text = ((DateTime)this.Application.RequestedDateTo).ToString("MM/dd/yyyy");
			}
			if( this.Application.LegalEntity != null )
			{
				this.ddlLegalEntity.SelectedValue = Application.LegalEntity.Id.ToString();
			}
			if(this.KnowledgeVisible)
			{
				this.TR_Knowledge.Visible = true;
				this.TR_KnowledgeTitle.Visible  =true;
				this.lbSummaryReadOnly.Text = this.Application.Summary;
			}
			if( this.Application.DepartmentName != null )
			{
				this.lbDepartmentReadOnly.Text = this.Application.DepartmentName.DepartmentCode;			
			}

			this.ApplicationNo = this.Application.AppNo;
			if(this.Application.RequestDate != null)
				this.RequestDate = (DateTime)this.Application.RequestDate;
//			this.ddlAccount.SelectedValue = this.Application.Account;
//			this.ddlCATBranch.SelectedValue = this.Application.AllDept;

			this.rbSomeoneElse.SelectedValue = this.Application.ApplyForSomeoneElse? "1":"0";
			if(this.Application.ApplyForSomeoneElse&&this.Application.SomeoneElseNo!=null)
			{

				this.Ctl_HRID.Text = this.Application.SomeoneElseHRID;
				this.SearchStaff.EmployeeID = this.Application.SomeoneElseNo.Id;
				this.SearchStaff.EmployeeName = this.Application.SomeoneElseNameEN;
				this.tbSomeoneTel.Text = this.Application.SomeoneElseTel;
				this.Ctl_SomeoneMobil.Text = this.Application.SomeoneElseMobil;
				this.tbSomeoneEmail.Text = this.Application.SomeoneElseEmail;
			}

			if(site != null && site.Rows.Count > 0)
			{
				for(int i=0; i<site.Rows.Count; i++)
					for(int j=0; j<this.cblPreferredLocation.Items.Count; j++)
					{
						if(site.Rows[i]["DicItemID"].ToString() == cblPreferredLocation.Items[j].Value)
							cblPreferredLocation.Items[j].Selected = true;
					}
			}				
		}

		private void BindCustomerInfoData(CustomerInfo customer)
		{
			if(customer != null)
			{
				this.tbCustomerName.Text = customer.Company;
				this.rbIsFCPA.SelectedValue = customer.IsFCPA? "1":"0";
				this.tbCustomerCountry.Text = customer.Country;
//				this.tbGuestNumber.Text = customer.NumberOfPerson; 
				this.tbVisitObjectives.Text = customer.VisitObjective;
				this.tbPotentialRevenue.Text = customer.DecryptedRevenuePotential.ToString();
				this.ddlPotentialRevenueTime.SelectedValue = customer.PotentialRevenueTimeframe.ToString();
				this.ddlSaleStage.SelectedValue = customer.SalesStage.ToString();

				this.rbOutStandingRFP.SelectedValue = customer.IsInRFP? "1":"0"; 
				this.Ctl_RFPDetails.Text = customer.RFPDetail;
				this.RB_IsSensitiveIssue.SelectedValue = customer.IsSensitiveIssue? "1":"0"; 
				this.tbSensitiveIssues.Text = customer.IsThereSensitiveIssue;
				this.RBL_KeyMessage.SelectedValue = customer.IsKeyMessage? "1":"0";
				this.tbKeyMessage.Text = customer.IsThereKeyMessage;


				this.tbCompanyProfile.Text = customer.CompanyProfile;
				this.ddlAccountType.SelectedValue = customer.AccountType.Id.ToString(); 
				this.tbProposalNo.Text = customer.ProposalNo;
			}
		}

		private void BindBusinessPurposeData(BusinessPurpose business)
		{
			if(business != null)
			{
				this.rbSalesContract.SelectedValue = business.IsInSalesContract? "1":"0";
				this.rbSalesContractSigned.SelectedValue = business.IsContractSigned? "1":"0"; 
				this.rbActivityInTrip.SelectedValue = business.RecreationalActivity? "1":"0";
				this.Ctl_DetailedItinerary.Text = business.Itinerary;
				this.tbNotSalesContractDescription.Text = business.Opportunities;
			}
		}

		private void BindTopicData(Topic topic)
		{
			if(topic != null)
			{
				this.tbTopic.Text = topic.TopicName;
			}
		}

		private void BindSalesTeamData(SalesTeamInfo salesTeam)
		{
			if(salesTeam != null)
			{
				this.tbCustomerTeamHost.Text = salesTeam.HostNameEN;
				this.tbCustomerOfficeTel.Text = salesTeam.OfficeTel;
				this.tbCustomerFax.Text = salesTeam.OfficeFax;
				this.tbCustomerEmail.Text = salesTeam.Email;
				this.ddlSalesBusinessUnit.SelectedValue = salesTeam.SalesBusinessUnit;
				this.ddlRegion.SelectedValue = salesTeam.Region;
			}
		}

		private void BindLogisticalData(LogisticalInfo logist)
		{
			if(logist != null)
			{
				this.Ctl_HotelComment.Text = logist.HotelComment;
				if(logist.DateRequiredFrom!=null)
				{
					this.tbDatesRequiredFrom.Text = ((DateTime)logist.DateRequiredFrom).ToString("MM/dd/yyyy");
				}
				if(logist.DateRequiredTo!=null)
				{
					this.tbDatesRequiredTo.Text = ((DateTime)logist.DateRequiredTo).ToString("MM/dd/yyyy");
				}
//				this.tbPriceRangeFrom.Text = logist.GiftPriceFrom.ToString();
//				this.tbPriceRangeTo.Text = logist.GiftPriceTo.ToString();
				this.RBL_Meal.SelectedValue = logist.IsMealReservation? "1":"0";
				this.Ctl_MealContent.Text = logist.MealReservation;
				this.Ctl_MealEachCost.Text = logist.AverageMealCost.ToString();

				this.Ctl_LogisticComment.Text = logist.Comment;

				//Arrival Fight No
				this.Ctl_ArrivalFlightNo.Text = logist.ArrivalFlightNo;
				this.Ctl_ArrivalAirport.Text = logist.ArrivalAirport;
				if(logist.ArrivalTime!=null&&logist.ArrivalTime!="")
				{
					this.ArrivalTime.Text = ((DateTime)logist.ArrivalTime).ToString("MM/dd/yyyy");
				}

				if(logist.MeetingRoom!=null)
				{
					this.Dp_MeetingRoom.SelectedIndex = Dp_MeetingRoom.Items.IndexOf(Dp_MeetingRoom.Items.FindByValue(logist.MeetingRoom.Id.ToString()));
				}

				//Leave Fight No
				this.Ctl_LeaveFlightNo.Text = logist.DepartureFlightNo;
				this.Ctl_LeaveAirport.Text = logist.DepartureAirport;
				if(logist.DepartureTime!=null&&logist.DepartureTime!="")
				{
					this.LeaveTime.Text = ((DateTime)logist.DepartureTime).ToString("MM/dd/yyyy");
				}

				this.rbEntertainmentNeed.SelectedValue = logist.IsNeedEntertainment? "1":"0";
				this.tbPreferEntertainment.Text = logist.EntertainmentPreference;
				this.tbEntertainmentPriceRangeFrom.Text = logist.DecryptedEntertainmentPriceFrom.ToString();
				this.tbEntertainmentPriceRangeTo.Text = logist.DecryptedEntertainmentPriceTo.ToString();

				this.tbGiftPriceRangeFrom.Text = logist.DecryptedGiftPriceFrom.ToString();
				this.tbGiftPriceRangeTo.Text = logist.DecryptedGiftPriceTo.ToString();

				this.rbGiftNeed.SelectedValue = logist.IsNeedGift? "1":"0"; 
				this.tbPreferGift.Text = logist.GiftDetails;
				//Gift Attachment
//				BEGDC.CC.BL.Common.IUtility utility = AppContainer.Instance[ServiceConst.UtilityService] as BEGDC.CC.BL.Common.IUtility;
//				string[] GiftAttInfo = utility.DisplayAppAttachments(this.AppID, BEGDC.CC.BL.CCFlow.AttachmentType.GIFT.ToString());
//				if(GiftAttInfo!=null)
//				{
//					this.GiftAttachment.Text = GiftAttInfo[0];
//					this.HiddenGiftAttachment.Text = GiftAttInfo[1];
//					this.GiftAttachment.Visible = true;
//				}
				this.rbReceivedGift.SelectedValue = logist.IsReceivedALGiftBefore? "1":"0";
				this.Ctl_GiftsDetails.Text = logist.ReceivedGiftDetails;

				this.rbCateringService.SelectedValue = logist.IsNeedCatering? "1":"0";
				this.tbCaterServiceExplain.Text = logist.CateringDescription;
				this.RB_IsTravelAgency.SelectedValue = logist.IsNeedTravelAgency? "1":"0";
				this.Ctl_TravelAgency.Text = logist.TravelAgency;
			}
		}

		private void BindHotelData(LogisticalInfo LogisticalInfo)
		{
			//HOTEL PREFERENCE
			//LOAD HOTEL LIST
			ICR CRService = AppContainer.Instance[ServiceConst.CRService] as ICR;
			DataTable HotelDataTable = null;
			//object SessHotelBooking = Session[SessionFlag.HotelSessionEZ];
			if(Session[SessionFlag.HotelSessionEZ]!=null)
			{
				object SessHotelBooking = Session[SessionFlag.HotelSessionEZ];
				HotelDataTable = (DataTable)SessHotelBooking;
				this.dgHotel.DataSource = HotelDataTable;
				this.dgHotel.DataBind();
			}
			else
			{
				if(LogisticalInfo!=null)
				{
					HotelDataTable = CRService.GetHotelRoomBookingList(LogisticalInfo.Id, false);
				}
				if(HotelDataTable!=null&&HotelDataTable.Rows.Count>0)
				{
					Session[SessionFlag.HotelSessionEZ] = HotelDataTable;
					//this.DG_Hotel.DataSource = HotelDataTable;
					//this.DG_Hotel.DataBind();
				}
				else
				{
					HotelDataTable = new DataTable();
					HotelDataTable.Columns.Add(new DataColumn("Id", typeof(System.String)));
					HotelDataTable.Columns.Add(new DataColumn("HotelId", typeof(System.String)));
					HotelDataTable.Columns.Add(new DataColumn("HotelName", typeof(System.String)));
					HotelDataTable.Columns.Add(new DataColumn("RoomTypeId", typeof(System.String)));
					HotelDataTable.Columns.Add(new DataColumn("RoomTypeName", typeof(System.String)));
					HotelDataTable.Columns.Add(new DataColumn("RoomNumber", typeof(System.String)));
					Session[SessionFlag.HotelSessionEZ] = HotelDataTable;
				}
				this.dgHotel.DataSource = HotelDataTable;
				this.dgHotel.DataBind();
			}
		}

		private void BindCompanyCarData(LogisticalInfo LogisticalInfo)
		{
			//COMPANY CAR
			//LOAD COMPANY CAR LIST
			ICR CRService = AppContainer.Instance[ServiceConst.CRService] as ICR;
			DataTable CompanyCarDataTable = null;
			object SessCompanyCarBooking = Session[SessionFlag.CompanyCarSessionEZ];
			if(SessCompanyCarBooking!=null)
			{
				CompanyCarDataTable = (DataTable)SessCompanyCarBooking;
				this.dgCompanyCar.DataSource = CompanyCarDataTable;
				this.dgCompanyCar.DataBind();
			}
			else
			{
				if(LogisticalInfo!=null)
				{
					CompanyCarDataTable = CRService.GetVehicleBookingList(LogisticalInfo.Id,BEGDC.CC.BL.Common.DicType.AlcatelCar);
				}
				if(CompanyCarDataTable!=null&&CompanyCarDataTable.Rows.Count>0)
				{
					Session[SessionFlag.CompanyCarSessionEZ] = CompanyCarDataTable;
				}
				else
				{
					CompanyCarDataTable = new DataTable();
					CompanyCarDataTable.Columns.Add(new DataColumn("Id", typeof(System.String)));
					CompanyCarDataTable.Columns.Add(new DataColumn("VehicleTypeId", typeof(System.String)));
					CompanyCarDataTable.Columns.Add(new DataColumn("VehicleType", typeof(System.String)));
					CompanyCarDataTable.Columns.Add(new DataColumn("VehicleNumber", typeof(System.String)));
					Session[SessionFlag.CompanyCarSessionEZ] = CompanyCarDataTable;
				}
				this.dgCompanyCar.DataSource = CompanyCarDataTable;
				this.dgCompanyCar.DataBind();
				//this.Lb_TotalPriceForCompanyCar.Text = CaculateTotalPriceForLeaseCar(CompanyCarDataTable);
			}
		}

		private void BindLeaseCarData(LogisticalInfo LogisticalInfo)
		{
			//LEASE CAR
			//LOAD LEASE CAR LIST
			ICR CRService = AppContainer.Instance[ServiceConst.CRService] as ICR;
			DataTable LeaseCarDataTable = null;
			object SessLeaseCarBooking = Session[SessionFlag.LeaseCarSessionEZ];
			if(SessLeaseCarBooking!=null)
			{
				LeaseCarDataTable = (DataTable)SessLeaseCarBooking;
				this.dgLeaseCar.DataSource = LeaseCarDataTable;
				this.dgLeaseCar.DataBind();
			}
			else
			{
				if(LogisticalInfo!=null)
				{
					LeaseCarDataTable = CRService.GetVehicleBookingList(LogisticalInfo.Id,BEGDC.CC.BL.Common.DicType.LeaseCar);
				}
				if(LeaseCarDataTable!=null&&LeaseCarDataTable.Rows.Count>0)
				{
					Session[SessionFlag.LeaseCarSessionEZ] = LeaseCarDataTable;
				}
				else
				{
					LeaseCarDataTable = new DataTable();
					LeaseCarDataTable.Columns.Add(new DataColumn("Id", typeof(System.String)));
					LeaseCarDataTable.Columns.Add(new DataColumn("VehicleTypeId", typeof(System.String)));
					LeaseCarDataTable.Columns.Add(new DataColumn("VehicleType", typeof(System.String)));
					LeaseCarDataTable.Columns.Add(new DataColumn("VehicleNumber", typeof(System.String)));
					Session[SessionFlag.LeaseCarSessionEZ] = LeaseCarDataTable;
				}
				this.dgLeaseCar.DataSource = LeaseCarDataTable;
				this.dgLeaseCar.DataBind();
				//this.Lb_TotalPriceForLeaseCar.Text = CaculateTotalPriceForLeaseCar(LeaseCarDataTable);
			}
		}

		private void BindPaymentData(PaymentInfo payment)
		{
			if(payment != null)
			{
				//this.ddlPayingFor.SelectedValue = payment.Payer.ToString();
				//this.rbDirectToProvider.SelectedValue = payment.IsPayServiceProvider? "1":"0";
				this.tbNotDirectReason.Text = payment.Comments;
				this.tbEstimateTotalCost.Text = payment.DecryptedEstimatedCustomerTotalCost.ToString();
				this.tbEstimateCostPerPerson.Text = payment.DecryptedEstimateCustomerdIndividualCost.ToString();
				this.Dp_ExpenseType.SelectedIndex = Dp_ExpenseType.Items.IndexOf(Dp_ExpenseType.Items.FindByValue(payment.ExpenseType.Id.ToString()));
				//this.tbNotDirectReason.Text = payment.CustomerPerdiem;
			}
		}

		private void BindContractInfo()
		{
			DataTable ContractInfo = null;
			if(Session[SessionFlag.ContractInfo] != null)
			{
				ContractInfo = (DataTable)Session[SessionFlag.ContractInfo];
			}
			else
			{
				if(this.AppID > 0)
				{
					IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
					ContractInfo = SetRowID(queryService.QueryContractInfoByAppId(this.AppID));
				}
				if(ContractInfo == null || ContractInfo.Rows.Count == 0)
				{
					ContractInfo = new DataTable();
					ContractInfo.Columns.Add(new DataColumn("RowId", typeof(System.String)));
					ContractInfo.Columns.Add(new DataColumn("DateOfContract", typeof(System.DateTime)));
					ContractInfo.Columns.Add(new DataColumn("ContractNo", typeof(System.String)));
					ContractInfo.Columns.Add(new DataColumn("ProducstSold", typeof(System.String)));
					ContractInfo.Columns.Add(new DataColumn("VisitPurposeInContract", typeof(System.String)));
					ContractInfo.Columns.Add(new DataColumn("Quotas", typeof(System.Int32)));
					ContractInfo.Columns.Add(new DataColumn("UnitPrice", typeof(System.Decimal)));
					ContractInfo.Columns.Add(new DataColumn("Budget", typeof(System.Decimal)));
				}
				Session[SessionFlag.ContractInfo] = ContractInfo;
			}
			this.dgContractInfo.DataSource = this.SetRowID(ContractInfo);
			this.dgContractInfo.DataBind();

			this.lbContractSum.Text = CalculateSum();
		}

		private DataTable SetRowID(DataTable table)
		{
			if(table != null && table.Rows.Count >0)
				for(int i=1; i<=table.Rows.Count; i++)
				{
					table.Rows[i-1][0] = i.ToString();
				}
			return table;
		}
		#endregion

		#region BindCustomerAttendee
		private void BindCustomerAttendee()
		{
			DataTable CustomerDataTable = null;
			object SessCustomerAttendee = Session[SessionFlag.CustomerSessionEZ];
			if(SessCustomerAttendee!=null)
			{
				CustomerDataTable = (DataTable)SessCustomerAttendee;
			}
			else
			{
				if(this.CustomerID > 0)
				{
					IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
					CustomerDataTable = queryService.GetCustomerAttendeeList(this.CustomerID);
				}
				if(CustomerDataTable!=null&&CustomerDataTable.Rows.Count>0)
				{
					Session[SessionFlag.CustomerSessionEZ] = CustomerDataTable;
				}
				else
				{
					CustomerDataTable = new DataTable();
					CustomerDataTable.Columns.Add(new DataColumn("Id", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("Name", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("Company", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("TitleEN", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("NameCN", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("CompanyEN", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("Title", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("Responsibility", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("Affects", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("ResponsibilityID", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("AffectsID", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("Remark", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("IsExisted", typeof(System.String)));
					Session[SessionFlag.CustomerSessionEZ] = CustomerDataTable;
				}
			}
			this.dgCustomerList.DataSource = this.SetRowID(CustomerDataTable);
			this.dgCustomerList.DataBind();
			if(CheckCISCustomer())
			{
				this.Lb_CISWarning.Visible = true;
			}
			else
			{
				this.Lb_CISWarning.Visible = false;
			}
			if(CustomerDataTable!=null&&CustomerDataTable.Rows.Count>0)
			{
				this.lbGuestNumberReadOnly.Text = CustomerDataTable.Rows.Count.ToString();
			}
			else
			{
				this.lbGuestNumberReadOnly.Text = "0";
			}
		}
		#endregion

		#region BindALAttendee
		private void BindALAttendee()
		{
			DataTable AccompanyingAttendee = null;
			if(Session[SessionFlag.AccompanySessionEZ] != null)
			{
				AccompanyingAttendee = (DataTable)Session[SessionFlag.AccompanySessionEZ];
			}
			else
			{
				if(this.AppID > 0)
				{
					ICR crService = AppContainer.Instance[ServiceConst.CRService] as ICR;
					AccompanyingAttendee = crService.GetAccompanyingAttendeeList(this.AppID);
				}
				if(AccompanyingAttendee == null || AccompanyingAttendee.Rows.Count == 0)
				{
					AccompanyingAttendee = new DataTable();
					AccompanyingAttendee.Columns.Add(new DataColumn("Id", typeof(System.String)));
					AccompanyingAttendee.Columns.Add(new DataColumn("EmployeeId", typeof(System.String)));
					AccompanyingAttendee.Columns.Add(new DataColumn("Name", typeof(System.String)));
					AccompanyingAttendee.Columns.Add(new DataColumn("Title", typeof(System.String)));
				}
				Session[SessionFlag.AccompanySessionEZ] = AccompanyingAttendee;
			}
			this.dgALAttendee.DataSource = this.SetRowID(AccompanyingAttendee);
			this.dgALAttendee.DataBind();
		}
		#endregion

		#region BindCostCenter
		private void BindCostCenter()
		{
			DataTable CostCenter = null;
			if(Session[SessionFlag.CostCenter] != null)
			{
				CostCenter = (DataTable)Session[SessionFlag.CostCenter];
			}
			else
			{
				if(this.PaymentID > 0)
				{
					IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
					CostCenter = queryService.GetCostCenter(this.PaymentID);
				}
				if(CostCenter == null || CostCenter.Rows.Count == 0)
				{
					CostCenter = new DataTable();
					CostCenter.Columns.Add(new DataColumn("Id", typeof(System.String)));
					CostCenter.Columns.Add(new DataColumn("CostCenterCode", typeof(System.String)));
					CostCenter.Columns.Add(new DataColumn("Cost", typeof(System.String)));
					CostCenter.Columns.Add(new DataColumn("ActualCost", typeof(System.String)));
					CostCenter.Columns.Add(new DataColumn("ActualTransferCost", typeof(System.String)));
				}
				Session[SessionFlag.CostCenter] = CostCenter;
			}
			this.dgCostCenter.DataSource = this.SetRowID(CostCenter);
			this.dgCostCenter.DataBind();

			this.lbCostSum.Text = this.CalculateCostSum();
		}
		#endregion

		#region BindReadOnlyStatus
		private void BindReadOnlyStatus()
		{
			this.ALPaneImg.Visible = false;
			this.CustomerPaneImg.Visible = false;
			this.CostCenterPaneImg.Visible = false;
			this.ConrtractInfoPane.Visible = false;
			// Application
			this.tbRequestorName.Visible = false;
			this.lbRequestorNameReadOnly.Text = this.tbRequestorName.Text;
			this.tbRequestOfficeTel.Visible = false;
			this.lbRequestOfficeTelReadOnly.Text = this.tbRequestOfficeTel.Text;
			this.tbRequestorMobile.Visible = false;
			this.lbRequestorMobileReadOnly.Text = this.tbRequestorMobile.Text;
			this.ddlLegalEntity.Visible = false;
			this.lblLegalEntity.Text = this.ddlLegalEntity.SelectedItem.Text;

            this.Dp_Department.Visible = false;
			if(this.Dp_Department.SelectedItem!=null)
			{
				this.tx_AllDepts.Text = this.Dp_Department.SelectedValue;
			}
			this.Dp_Account.Visible = false;
			if(this.Dp_Account.SelectedItem!=null)
			{
				this.tx_Account.Text = this.Dp_Account.SelectedValue;
			}

			this.rbReviewGuideLine.Visible = false;
			this.lbReviewGuideLineReadOnly.Text = this.rbReviewGuideLine.SelectedItem.Text;
			this.tbOtherLocation.Visible = false;
			this.lbOtherLocationReadOnly.Text = this.tbOtherLocation.Text;
			//this.tbOtherCountry.Visible = false;
			//this.lbOtherCountryReadOnly.Text = this.tbOtherCountry.Text;
			this.tbRequestedDateFrom.Visible = false;
			this.lbRequestedDateFromReadOnly.Text = this.tbRequestedDateFrom.Text;
			this.tbRequestedDateTo.Visible = false;
			this.lbRequestedDateToReadOnly.Text = this.tbRequestedDateTo.Text;

			this.Ctl_HRID.Visible = false;
			this.LB_HRID.Text = this.Ctl_HRID.Text;
			this.rbSomeoneElse.Visible = false;
			this.lbSomeoneElseReadOnly.Text = this.rbSomeoneElse.SelectedItem.Text;
			this.SearchStaff.Visible = false;
			this.lbSomeoneNameReadOnly.Text = this.SearchStaff.EmployeeName;
			this.Ctl_SomeoneMobil.Visible = false;
			this.Lb_SomeoneMobil.Text = this.Ctl_SomeoneMobil.Text;
			this.tbSomeoneTel.Visible = false;
			this.lbSomeoneTelReadOnly.Text = this.tbSomeoneTel.Text;
			this.tbSomeoneEmail.Visible = false;
			this.lbSomeoneEmailReadOnly.Text = this.tbSomeoneEmail.Text;
			this.cblPreferredLocation.Visible = false;
			for(int i=0; i<this.cblPreferredLocation.Items.Count; i++)
				if(cblPreferredLocation.Items[i].Selected)
					this.lbPreferredLocationReadOnly.Text += cblPreferredLocation.Items[i].Text + ",";
			string temp = this.lbPreferredLocationReadOnly.Text;
			if(temp != string.Empty)
				this.lbPreferredLocationReadOnly.Text = temp.Substring(0, temp.Length -1);
            //ContractDateImg.Visible = false;
			
			// Customer
			this.tbCustomerName.Visible = false;
			this.lbCustomerNameReadOnly.Text = this.tbCustomerName.Text;
			this.rbIsFCPA.Visible = false;
			this.lbIsFCPAReadOnly.Text = this.rbIsFCPA.SelectedItem.Text;
			this.tbCustomerCountry.Visible = false;
			this.lbCustomerCountryReadOnly.Text = this.tbCustomerCountry.Text;
//			this.tbGuestNumber.Visible = false;
//			this.lbGuestNumberReadOnly.Text = this.tbGuestNumber.Text;
			this.tbVisitObjectives.Visible = false;
			this.lbVisitObjectivesReadOnly.Text = this.tbVisitObjectives.Text;
			this.tbPotentialRevenue.Visible = false;
			this.lbPotentialRevenueReadOnly.Text = this.tbPotentialRevenue.Text;
			this.ddlPotentialRevenueTime.Visible = false;
			this.lbPotentialRevenueTimeReadOnly.Text = this.ddlPotentialRevenueTime.SelectedItem.Text;
			this.ddlSaleStage.Visible = false;
			this.lbSaleStageReadOnly.Text = this.ddlSaleStage.SelectedItem.Text;

			this.rbOutStandingRFP.Visible = false;
			this.lbOutStandingRFPReadOnly.Text = this.rbOutStandingRFP.SelectedItem.Text;
			//--
			this.Ctl_RFPDetails.Visible = false;
			this.Lb_RFPDetails.Text = this.Ctl_RFPDetails.Text;
			//--
			this.RB_IsSensitiveIssue.Visible = false;
			this.lbIsSensitiveIssue.Text = this.RB_IsSensitiveIssue.SelectedItem.Text;
			this.tbSensitiveIssues.Visible = false;
			this.lbSeneitiveIssuesReadOnly.Text = this.tbSensitiveIssues.Text;

			this.RBL_KeyMessage.Visible = false;
			this.lbKeyMessage.Text = this.RBL_KeyMessage.SelectedItem.Text;
			this.tbKeyMessage.Visible = false;
			this.lbKeyMessageReadOnly.Text = this.tbKeyMessage.Text;


			this.tbCompanyProfile.Visible = false;
			this.lbCompanyProfileReadOnly.Text = this.tbCompanyProfile.Text;
			this.ddlAccountType.Visible = false;
			this.lbAccountTypeReadOnly.Text = this.ddlAccountType.SelectedItem.Text;
			this.tbProposalNo.Visible = false;
			this.lbProposalNoReadOnly.Text = this.tbProposalNo.Text;

		    tbRequestedDateToSpan.Visible = false;
            tbRequestedDateFromSpan.Visible = false;
			tbDatesRequiredFromSpan.Visible = false;
			tbDatesRequiredToSpan.Visible = false;


			// Business Purpose
			this.rbSalesContract.Visible = false;
			this.lbSalesContractReadOnly.Text = this.rbSalesContract.SelectedItem.Text;
			this.rbSalesContractSigned.Visible = false;
			this.lbSalesContractSignedReadOnly.Text = this.rbSalesContractSigned.SelectedItem.Text;
			this.tbNotSalesContractDescription.Visible = false;
			this.lbNotSalesContractDescriptionReadOnly.Text = this.tbNotSalesContractDescription.Text;
			this.rbActivityInTrip.Visible = false;
			this.lbActivityInTripReadOnly.Text = this.rbActivityInTrip.SelectedItem.Text;
			//--
			this.Ctl_DetailedItinerary.Visible = false;
			this.Lb_DetailedItinerary.Text = this.Ctl_DetailedItinerary.Text;

			this.tbTopic.Visible = false;
			this.lbTopicReadOnly.Text = this.tbTopic.Text;
			// Sales Team
			this.tbCustomerTeamHost.Visible = false;
			this.lbCustomerTeamHostReadOnly.Text = this.tbCustomerTeamHost.Text;
			this.tbCustomerOfficeTel.Visible = false;
			this.lbCustomerOfficeTelReadOnly.Text = this.tbCustomerOfficeTel.Text;
			this.tbCustomerFax.Visible = false;
			this.lbCustomerFaxReadOnly.Text = this.tbCustomerFax.Text;
			this.tbCustomerEmail.Visible = false;
			this.lbCustomerEmailReadOnly.Text = this.tbCustomerEmail.Text;
			this.ddlSalesBusinessUnit.Visible = false;
			this.lbSalesBusinessUnitReadOnly.Text = this.ddlSalesBusinessUnit.SelectedItem.Text;
			this.ddlRegion.Visible = false;
			this.lbRegionReadOnly.Text = this.ddlRegion.SelectedItem.Text;

			// LogisticalInfo
			this.Dp_MeetingRoom.Visible = false;
			if(this.Dp_MeetingRoom.SelectedItem!=null)
			{
				this.tx_MeetingRoom.Text = this.Dp_MeetingRoom.SelectedItem.Text;
			}
			this.RBL_Meal.Visible = false;
			this.Lb_IsMealReservation.Text = this.RBL_Meal.SelectedItem.Text;

			this.Ctl_HotelComment.Visible = false;
			this.lbhotelcomment.Text = this.Ctl_HotelComment.Text;

			this.Ctl_MealContent.Visible = false;
			this.tx_MealContent.Text = this.Ctl_MealContent.Text;
			this.Ctl_MealEachCost.Visible = false;
			this.LB_MealEachCost.Text = this.Ctl_MealEachCost.Text;
			this.Ctl_LogisticComment.Visible = false;
			this.lbLogisticComment.Text = this.Ctl_LogisticComment.Text;

			//Fight Train info
			this.Ctl_ArrivalFlightNo.Visible = false;
			this.tx_ArrivalFightNo.Text = this.Ctl_ArrivalFlightNo.Text;
			this.Ctl_ArrivalAirport.Visible = false;
			this.tx_ArrivalAirport.Text = this.Ctl_ArrivalAirport.Text;
			this.ArrivalTime.Visible = false;
			this.tx_ArrivalTime.Text = this.ArrivalTime.Text;
			this.Ctl_LeaveFlightNo.Visible = false;
			this.tx_LeaveFightNo.Text = this.Ctl_LeaveFlightNo.Text;
			this.Ctl_LeaveAirport.Visible = false;
			this.tx_LeaveAirport.Text = this.Ctl_LeaveAirport.Text;
			this.LeaveTime.Visible = false;
			this.tx_LeaveTime.Text = this.LeaveTime.Text;


			this.tbDatesRequiredFrom.Visible = false;
			this.lbDatesRequiredFromReadOnly.Text = this.tbDatesRequiredFrom.Text;
			this.tbDatesRequiredTo.Visible = false;
			this.lbDatesRequiredToReadOnly.Text = this.tbDatesRequiredTo.Text;
			this.rbEntertainmentNeed.Visible = false;
			this.lbEntertainmentNeedReadOnly.Text = this.rbEntertainmentNeed.SelectedItem.Text;
			this.tbPreferEntertainment.Visible = false;
			this.lbPreferEntertainmentReadOnly.Text = this.tbPreferEntertainment.Text;
			this.tbEntertainmentPriceRangeFrom.Visible = false;
			this.lbEntertainmentPriceRangeFromReadOnly.Text = this.tbEntertainmentPriceRangeFrom.Text;
			this.tbEntertainmentPriceRangeTo.Visible = false;
			this.lbEntertainmentPriceRangeToReadOnly.Text = this.tbEntertainmentPriceRangeTo.Text;

			this.rbGiftNeed.Visible = false;
			this.lbGiftNeedReadOnly.Text = this.rbGiftNeed.SelectedItem.Text;
			this.tbPreferGift.Visible = false;
			this.lbPreferGiftReadOnly.Text = this.tbPreferGift.Text;
			this.tbGiftPriceRangeFrom.Visible = false;
			this.lbGiftPriceRangeFromReadOnly.Text = this.tbGiftPriceRangeFrom.Text;
			this.tbGiftPriceRangeTo.Visible = false;
			this.lbGiftPriceRangeToReadOnly.Text = this.tbGiftPriceRangeTo.Text;

			this.rbReceivedGift.Visible = false;
			this.lbReceivedGiftReadOnly.Text = this.rbReceivedGift.SelectedItem.Text;
			this.Ctl_GiftsDetails.Visible = false;
			this.Lb_GiftDetails.Text = this.Ctl_GiftsDetails.Text;

			this.rbCateringService.Visible = false;
			this.lbCateringServiceReadOnly.Text = this.rbCateringService.SelectedItem.Text;
			this.tbCaterServiceExplain.Visible = false;
			this.lbCaterServiceExplainReadOnly.Text = this.tbCaterServiceExplain.Text;

			ArrivalTimeSpan.Visible = false;
			LeaveTimeSpan.Visible = false;

			HotelBookingImg.Visible = false;
			CompanyCarImg.Visible = false;
			LeaseCarImg.Visible = false;

			this.RB_IsTravelAgency.Visible = false;
			this.Lb_IsTravelAgency.Text = this.RB_IsTravelAgency.SelectedItem.Text;

			this.Ctl_TravelAgency.Visible = false;
			this.Lb_TravelAgency.Text = this.Ctl_TravelAgency.Text;

			this.rbCateringService.Visible = false;
			this.lbCateringServiceReadOnly.Text = this.rbCateringService.SelectedItem.Text;

			this.tbCaterServiceExplain.Visible = false;
			this.lbCaterServiceExplainReadOnly.Text = this.tbCaterServiceExplain.Text;

			// Payment Info
			this.tbNotDirectReason.Visible = false;
			this.lbNotDirectReasonReadOnly.Text = this.tbNotDirectReason.Text;
			this.tbEstimateTotalCost.Visible = false;
			this.lbEstimateTotalCostReadOnly.Text = this.tbEstimateTotalCost.Text;
			this.tbEstimateCostPerPerson.Visible = false;
			this.lbEstimateCostPerPersonReadOnly.Text = this.tbEstimateCostPerPerson.Text;
			this.Dp_ExpenseType.Visible = false;
			this.lbExpenseTypeReadOnly.Text = this.Dp_ExpenseType.SelectedItem.Text;

			//this.tbReason.Visible = false;
			//this.lbReasonReadOnly.Text = this.tbReason.Text;



			this.dgContractInfo.Columns[8].Visible =false;
			this.dgCustomerList.Columns[6].Visible = false;
			this.dgALAttendee.Columns[3].Visible = false;
			this.dgHotel.Columns[6].Visible = false;
			this.dgCompanyCar.Columns[4].Visible = false;
			this.dgLeaseCar.Columns[4].Visible = false;
			this.dgCostCenter.Columns[3].Visible = false;
		
		}
		#endregion

		#region CaculateTotalPriceForLeaseCar
		private string CaculateTotalPriceForLeaseCar(DataTable dataTable)
		{
			ICR CRService = AppContainer.Instance[ServiceConst.CRService] as ICR;
			double Total = 0;
			int VID = 0;
			int Quat = 0;
			double UnitPrice = 0;
			BEGDC.CC.Entity.VehicleType vehicle = null;
			if(dataTable==null||dataTable.Rows.Count==0) return Total.ToString();
			for(int i=0;i<dataTable.Rows.Count;i++)
			{
				VID = Convert.ToInt32(dataTable.Rows[i]["VehicleTypeId"].ToString());
				vehicle = CRService.GetVehicleType(VID);
				UnitPrice = Convert.ToDouble(vehicle.Price);
				Quat = Convert.ToInt32(dataTable.Rows[i]["VehicleNumber"].ToString());
				Total += UnitPrice*Quat;
			}
			return Total.ToString();
		}
		#endregion

		#region BuildApplication
		public void BuildApplication(ref Application app, ref CustomerInfo customer, ref BusinessPurpose business, 
			ref Topic topic, ref SalesTeamInfo salesTeam, ref LogisticalInfo logist, ref PaymentInfo payment, 
			ref IList customerAttendee, ref IList alAttendee, ref IList site, ref IList cost, ref IList contract, ref DataTable HotelTable, ref DataTable CompanyCarTable, ref DataTable LeaseCarTable)
		{
			//app.Id = this.AppID;
			app.EZVisitReqNo = string.Empty;
			app.LGDNo = string.Empty;
			app.ApplicationType = WorkflowTypes.CR;
			app.RequesterOfficeTel = this.tbRequestOfficeTel.Text.Trim();
			app.RequesterMobile = this.tbRequestorMobile.Text.Trim();

			if(this.Dp_Department.SelectedItem!=null)
			{
				app.AllDept = this.Dp_Department.SelectedValue.ToString();
			}
			if(this.Dp_Account.SelectedItem!=null)
			{
				app.Account = this.Dp_Account.SelectedValue.ToString();
			}
			if(this.ddlLegalEntity.SelectedItem!=null)
			{
				app.LegalEntity = new LegalEntity();
				app.LegalEntity.Id = Convert.ToInt32(this.ddlLegalEntity.SelectedValue);
			}
			
			IQuery query = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
			BEGDC.CC.Entity.Department dept = query.GetDepartmentByCode(this.Dp_Department.SelectedValue.ToString());

			if((dept!=null && (dept.DepartmentType.DicItemKey == BEGDC.CC.BL.Common.SysDicItem.DepartmentType.CAT)) || (this.Dp_Department.SelectedValue.ToString() == "OTH"))
			{
				//app.AllDept  = "HQ"+this.Dp_Department.SelectedValue.ToString();
				app.Account = string.Empty;
			}

			app.IsReviewedGuideline = this.rbReviewGuideLine.SelectedValue == "1";
			app.OtherSite = this.tbOtherLocation.Text.Trim();
			app.RequesterNameEN = this.tbRequestorName.Text.Trim();
			if(this.tbRequestedDateFrom.Text!="")
			{
				app.RequestedDateFrom = Convert.ToDateTime(this.tbRequestedDateFrom.Text);
			}
			if(this.tbRequestedDateTo.Text!="")
			{
				app.RequestedDateTo = Convert.ToDateTime(this.tbRequestedDateTo.Text);
			}

			IUser userService = AppContainer.Instance[ServiceConst.UserService] as IUser;
			app.RequesterNo = userService.GetUser(app.RequesterNameEN);
			app.RequestDate = this.RequestDate;
			
			// Apply for someone else
			bool applyForSomeElse = this.rbSomeoneElse.SelectedValue == "1";
			app.ApplyForSomeoneElse = applyForSomeElse;
			if(applyForSomeElse)
			{
				if(this.SearchStaff.EmployeeName == string.Empty)
				{
					Page.RegisterClientScriptBlock("","<script>alert('Name of someone else should be specified.');</script>");
					return ;
				}
				if(this.SearchStaff.EmployeeName != string.Empty)
				{
					app.DepartmentName = this.GetUser(this.SearchStaff.EmployeeName).Department;
					app.SomeoneElseNo = new Employee();
					app.SomeoneElseNo.Id = this.SearchStaff.EmployeeID;
					app.SomeoneElseNameEN = this.SearchStaff.EmployeeName;
				}
				app.SomeoneElseHRID = this.Ctl_HRID.Text.Trim();
				app.SomeoneElseTel = this.tbSomeoneTel.Text.Trim();
				app.SomeoneElseMobil = this.Ctl_SomeoneMobil.Text.Trim();
				app.SomeoneElseEmail = this.tbSomeoneEmail.Text.Trim();
			}
			else
			{
				app.DepartmentName = this.GetUser(app.RequesterNameEN).Department;

				app.SomeoneElseHRID = string.Empty;
				app.SomeoneElseNo = null;
				app.SomeoneElseNameEN = string.Empty;
				app.SomeoneElseTel = string.Empty;
				app.SomeoneElseMobil = string.Empty;
				app.SomeoneElseEmail = string.Empty;
			}

			// Customer Info
			customer.Id = this.CustomerID;
			customer.Company = this.tbCustomerName.Text.Trim();
			customer.IsFCPA = this.rbIsFCPA.SelectedValue == "1";
			customer.Country = this.tbCustomerCountry.Text.Trim();
//			customer.NumberOfPerson = this.tbGuestNumber.Text.Trim();
			customer.VisitObjective = this.tbVisitObjectives.Text.Trim();
			if(WebUtility.IsNumber(this.tbPotentialRevenue.Text))
			{
				customer.DecryptedRevenuePotential = Convert.ToDecimal(this.tbPotentialRevenue.Text);
			}
			if(this.ddlPotentialRevenueTime.SelectedItem!=null)
			{
				customer.PotentialRevenueTimeframe = Convert.ToInt32(this.ddlPotentialRevenueTime.SelectedValue);
			}
			if(this.ddlSaleStage.SelectedItem!=null)
			{
				customer.SalesStage = Convert.ToInt32(this.ddlSaleStage.SelectedValue);
			}

			bool ISRFP = this.rbOutStandingRFP.SelectedValue == "1";
			customer.IsInRFP = ISRFP;
			if(ISRFP)
			{
				customer.RFPDetail = this.Ctl_RFPDetails.Text;
			}
			else
			{
				customer.RFPDetail = string.Empty;
			}
			bool ISSensiveIssue = this.RB_IsSensitiveIssue.SelectedValue == "1";
			customer.IsSensitiveIssue = ISSensiveIssue;
			if(ISSensiveIssue)
			{
				customer.IsThereSensitiveIssue = this.tbSensitiveIssues.Text;
			}
			else
			{
				customer.IsThereSensitiveIssue = string.Empty;
			}
			bool ISKEYMessage = this.RB_IsSensitiveIssue.SelectedValue == "1";
			customer.IsKeyMessage = ISKEYMessage;
			if(ISKEYMessage)
			{
				customer.IsThereKeyMessage = this.tbKeyMessage.Text;
			}
			else
			{
				customer.IsThereKeyMessage = string.Empty;
			}

			customer.CompanyProfile = this.tbCompanyProfile.Text.Trim();
			customer.AccountType = new DicItem();
			if(this.ddlAccountType.SelectedItem!=null)
			{
				customer.AccountType.Id = Convert.ToInt32(this.ddlAccountType.SelectedValue);
			}
			customer.ProposalNo = this.tbProposalNo.Text.Trim();

			// BusinessPurpose
			business.Id = this.BusinessID;
			bool ISContract = this.rbSalesContract.SelectedValue == "1";
			business.IsInSalesContract = ISContract;
			if(ISContract)
			{
				bool ISSIGNED = this.rbSalesContractSigned.SelectedValue == "1";
				business.IsContractSigned = ISSIGNED;
				if(ISSIGNED)
				{
					// Contract Info
					DataTable contracttable = (DataTable)this.dgContractInfo.DataSource;
					if(contracttable != null && contracttable.Rows.Count > 0)
					{
						for(int i=0;i<contracttable.Rows.Count;i++)
						{
							ContractInfo ci = new ContractInfo();
							ci.DateOfContract = Convert.ToDateTime(contracttable.Rows[i]["DateOfContract"]);
							ci.ContractNo = contracttable.Rows[i]["ContractNo"].ToString();
							ci.ProducstSold = contracttable.Rows[i]["ProducstSold"].ToString();
							ci.VisitPurposeInContract = contracttable.Rows[i]["VisitPurposeInContract"].ToString();
							ci.Quotas = Convert.ToInt32(contracttable.Rows[i]["Quotas"]);
							ci.UnitPrice = Convert.ToDecimal(contracttable.Rows[i]["UnitPrice"]);
							ci.Budget = Convert.ToDecimal(contracttable.Rows[i]["Budget"]);
			
							contract.Add(ci);
						}
					}
				}
			}
			else
			{
				business.IsContractSigned = false;
				business.Opportunities = this.tbNotSalesContractDescription.Text;
				business.Itinerary = this.tbNotSalesContractDescription.Text;
			}

			//business.IsContractSigned = this.rbSalesContractSigned.SelectedValue == "1";

//			business.DateOfContract = Convert.ToDateTime(this.tbContractDate.Text);
//			business.ContractNo = this.tbContractNo.Text.Trim();
//			business.ProductsSold = this.tbContractProducts.Text.Trim();
//			business.VisitPurposeInContract = this.tbContractTripPurpose.Text.Trim();
//			business.Quotas = Convert.ToInt32(this.tbContractQuotas.Text);
//			business.UnitPrice = Convert.ToDecimal(this.tbUnitPrice.Text);
//			business.Opportunities = this.tbNotSalesContractDescription.Text.Trim();
			bool ISACTIVITY = this.rbActivityInTrip.SelectedValue == "1";
			business.RecreationalActivity = ISACTIVITY;
			if(ISACTIVITY)
			{
				business.Itinerary = this.Ctl_DetailedItinerary.Text;
			}
			else
			{
				business.Itinerary = string.Empty;
			}

			topic.Id = this.TopicID;
			topic.TopicName = this.tbTopic.Text.Trim();

			// SalesTeam
			salesTeam.Id = this.SalesTeamID;
			salesTeam.HostNameEN = this.tbCustomerTeamHost.Text.Trim();
			salesTeam.OfficeTel = this.tbCustomerOfficeTel.Text.Trim();
			salesTeam.OfficeFax = this.tbCustomerFax.Text.Trim();
			salesTeam.Email = this.tbCustomerEmail.Text.Trim();
			if(this.ddlSalesBusinessUnit.SelectedItem!=null)
			{
				salesTeam.SalesBusinessUnit = this.ddlSalesBusinessUnit.SelectedValue;
			}
			if(this.ddlRegion.SelectedItem!=null)
			{
				salesTeam.Region = this.ddlRegion.SelectedValue;
			}

			// LogisticalInfo
			logist.Id = this.LogistID;

			logist.HotelComment = this.Ctl_HotelComment.Text;

			if(this.tbDatesRequiredFrom.Text!="")
			{
				logist.DateRequiredFrom = Convert.ToDateTime(this.tbDatesRequiredFrom.Text);
			}
			if(this.tbDatesRequiredTo.Text!="")
			{
				logist.DateRequiredTo = Convert.ToDateTime(this.tbDatesRequiredTo.Text);
			}
			IUtility utiService = AppContainer.Instance[ServiceConst.UtilityService] as IUtility;
			logist.MeetingRoom = utiService.GetDicItem(Convert.ToInt32(this.Dp_MeetingRoom.SelectedItem.Value));

			bool ISMEAL = this.RBL_Meal.SelectedValue == "1";
			logist.IsMealReservation = ISMEAL;
			if(ISMEAL)
			{
				logist.MealReservation = this.Ctl_MealContent.Text;
				if(WebUtility.IsNumber(this.Ctl_MealEachCost.Text))
				{
					logist.AverageMealCost = Convert.ToDecimal(this.Ctl_MealEachCost.Text);
				}
			}
			else
			{
				logist.MealReservation = string.Empty;
				logist.AverageMealCost = 0;
			}

			logist.Comment = this.Ctl_LogisticComment.Text;

			// Flight Info
			logist.ArrivalFlightNo = this.Ctl_ArrivalFlightNo.Text;
			logist.DepartureFlightNo = this.Ctl_LeaveFlightNo.Text;
            
			logist.ArrivalAirport = this.Ctl_ArrivalAirport.Text;
			logist.DepartureAirport = this.Ctl_LeaveAirport.Text;

			string ArrivalTime = this.ArrivalTime.Text;
			if(ArrivalTime!="")
			{
				logist.ArrivalTime = Nullables.NullableDateTime.Parse(ArrivalTime); 
			}
			string DepartureTime = this.LeaveTime.Text;
			if(DepartureTime!="")
			{
				logist.DepartureTime = Nullables.NullableDateTime.Parse(DepartureTime); 
			}

			bool ISPREFERENCE = this.rbEntertainmentNeed.SelectedValue == "1";
			logist.IsNeedEntertainment = ISPREFERENCE;
			if(ISPREFERENCE)
			{
				logist.EntertainmentPreference = this.tbPreferEntertainment.Text.Trim();
			}
			else
			{
				logist.EntertainmentPreference = string.Empty;
			}

			bool ISGIFT = this.rbGiftNeed.SelectedValue == "1";
			logist.IsNeedGift = ISGIFT;
			if(ISGIFT)
			{
				logist.GiftDetails = this.tbPreferGift.Text;
			}
			else
			{
				logist.GiftDetails = string.Empty;
			}
			//this.Ctl_GiftsDetails.Text = logist.GiftDetails;

			if(WebUtility.IsNumber(this.tbEntertainmentPriceRangeFrom.Text))
			{
				logist.DecryptedEntertainmentPriceFrom = Convert.ToDecimal(this.tbEntertainmentPriceRangeFrom.Text);
			}
			if(WebUtility.IsNumber(this.tbEntertainmentPriceRangeTo.Text))
			{
				logist.DecryptedEntertainmentPriceTo = Convert.ToDecimal(this.tbEntertainmentPriceRangeTo.Text);
			}
			
			if(WebUtility.IsNumber(this.tbGiftPriceRangeFrom.Text))
			{
				logist.DecryptedGiftPriceFrom = Convert.ToDecimal(this.tbGiftPriceRangeFrom.Text);
			}
			if(WebUtility.IsNumber(this.tbGiftPriceRangeTo.Text))
			{
				logist.DecryptedGiftPriceTo = Convert.ToDecimal(this.tbGiftPriceRangeTo.Text);
			}

			bool ISRECEIVEDGIFT = this.rbReceivedGift.SelectedValue == "1";
			logist.IsReceivedALGiftBefore = ISRECEIVEDGIFT;
			if(ISRECEIVEDGIFT)
			{
				logist.ReceivedGiftDetails = this.Ctl_GiftsDetails.Text.Trim();
			}
			else
			{
				logist.ReceivedGiftDetails = string.Empty;
			}

			
			bool ISAGENCY = this.RB_IsTravelAgency.SelectedValue == "1";
			logist.IsNeedTravelAgency = ISAGENCY;
			if(ISAGENCY)
			{
				logist.TravelAgency = this.Ctl_TravelAgency.Text.Trim();
			}
			else
			{
				logist.TravelAgency = string.Empty;
			}

			bool ISCATERING = this.rbCateringService.SelectedValue == "1";
			logist.IsNeedCatering = ISCATERING;
			if(ISCATERING)
			{
				logist.CateringDescription = this.tbCaterServiceExplain.Text.Trim();
			}
			else
			{
				logist.CateringDescription = string.Empty;
			}

			// Payment Info
			payment.Id = this.PaymentID;
			payment.Comments = this.tbNotDirectReason.Text.Trim();
			if(WebUtility.IsNumber(this.tbEstimateTotalCost.Text))
			{
				payment.DecryptedEstimatedCustomerTotalCost = Convert.ToDecimal(this.tbEstimateTotalCost.Text);
			}
			if(WebUtility.IsNumber(this.tbEstimateCostPerPerson.Text))
			{
				payment.DecryptedEstimateCustomerdIndividualCost = Convert.ToDecimal(this.tbEstimateCostPerPerson.Text);
			}
			payment.ExpenseType = utiService.GetDicItem(Convert.ToInt32(this.Dp_ExpenseType.SelectedValue));
			payment.CustomerPerdiem = string.Empty;

			// site info
			string VenueInfo = string.Empty;
			for(int i=0;i<this.cblPreferredLocation.Items.Count;i++)
			{
				if(cblPreferredLocation.Items[i].Selected)
				{
					AppVisitingSite appSite = new AppVisitingSite();
					appSite.Site = new DicItem();
					appSite.Site.Id = Convert.ToInt32(cblPreferredLocation.Items[i].Value);

					site.Add(appSite);
					VenueInfo += cblPreferredLocation.Items[i].Text + ",";
				}
			}
			if(VenueInfo.Length > 0)
				VenueInfo = VenueInfo.TrimEnd(',');
//			VenueInfo = VenueInfo.Substring(0,100);
			customer.Venue = VenueInfo;
			


			// Customer Attendee Info
			DataTable table = (DataTable)this.dgCustomerList.DataSource;
			if(table != null && table.Rows.Count > 0)
			{
				for(int i=0;i<table.Rows.Count;i++)
				{
					CustomerAttendee cus = new CustomerAttendee();
					cus.NameEN = table.Rows[i]["Name"].ToString();
					cus.Title = table.Rows[i]["Title"].ToString();
					cus.Company = table.Rows[i]["Company"].ToString();			
					cus.NameCN = table.Rows[i]["NameCN"].ToString();
					cus.TitleEN = table.Rows[i]["TitleEN"].ToString();
					cus.CompanyEN = table.Rows[i]["CompanyEN"].ToString();				
					cus.Responsibility = new DicItem();
					cus.Responsibility.Id =	Convert.ToInt32(table.Rows[i]["ResponsibilityID"]);
					cus.Affects = new DicItem();
					cus.Affects.Id = Convert.ToInt32(table.Rows[i]["AffectsID"]);
					cus.IsAttended = true;

					cus.Remark = table.Rows[i]["Remark"].ToString();
					cus.IsExisted = Convert.ToInt32(table.Rows[i]["IsExisted"]);

					customerAttendee.Add(cus);
				}
			}
			if(this.dgCustomerList.Items.Count>0)
			{
				customer.NumberOfPerson = this.dgCustomerList.Items.Count.ToString(); 
			}

			// AL Attendee Info
			table = (DataTable)this.dgALAttendee.DataSource;
			if(table != null && table.Rows.Count > 0)
			{
				for(int i=0;i<table.Rows.Count;i++)
				{
					ALAttendee al = new ALAttendee();
					al.EmployeeId = new Employee();
					al.EmployeeId.Id = table.Rows[i]["EmployeeId"].ToString();
					al.Title = table.Rows[i]["Title"].ToString();
			
					alAttendee.Add(al);
				}
			}

			// NEW UPDATE JOVI
			HotelTable = (DataTable)this.dgHotel.DataSource;
			CompanyCarTable = (DataTable)this.dgCompanyCar.DataSource;
			LeaseCarTable = (DataTable)this.dgLeaseCar.DataSource;

			// Cost Center Info
			table = (DataTable)this.dgCostCenter.DataSource;
			if(table != null && table.Rows.Count > 0)
			{
				for(int i=0;i<table.Rows.Count;i++)
				{
					CostCenterRelatedCost co = new CostCenterRelatedCost();
					co.CostCenterCode = table.Rows[i]["CostCenterCode"].ToString();
					co.DecryptedCost = Convert.ToDecimal(table.Rows[i]["Cost"]);
					co.CostType = CostType.Budget;
			
					cost.Add(co);
				}
			}
		}
		#endregion

		#region ItemDataBound

		private void dgCustomerList_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
			{
				ImageButton Btn_Edit = (ImageButton) e.Item.Cells[5].FindControl("Btn_Edit");
				string ItemId = e.Item.Cells[0].Text.ToString();
				Btn_Edit.Attributes.Add("onclick", "OpenCustomerPane('"+ItemId+"');");
				Btn_Edit.Attributes.Add("check", "false");

				ImageButton ld = (ImageButton)e.Item.Cells[6].FindControl("Btn_Delete");
				if(ld != null)
				{
					ld.Attributes.Add("onclick","On_Submit();");
					ld.Attributes.Add("check", "false");
				}

				string IsExisted = e.Item.Cells[7].Text.ToString();
				if(IsExisted==BEGDC.CC.BL.Common.CISFlag.NotExisted)
				{
					System.Web.UI.WebControls.Image WarningImg = (System.Web.UI.WebControls.Image) e.Item.Cells[8].FindControl("CISWarning");
					WarningImg.Visible = true;
				}
			}
		}
		
		private void dgALAttendee_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
			{
				ImageButton Btn_Edit = (ImageButton) e.Item.Cells[3].FindControl("Btn_ALEdit");
				string ItemId = e.Item.Cells[0].Text.ToString();
				Btn_Edit.Attributes.Add("onclick", "OpenALAttendeePane('"+ItemId+"');");
				Btn_Edit.Attributes.Add("check", "false");

				ImageButton ld = (ImageButton)e.Item.Cells[3].FindControl("Btn_ALDelete");
				if(ld != null)
				{
					ld.Attributes.Add("onclick","On_Submit();");
					ld.Attributes.Add("check", "false");
				}
			}
		}

		
		private void dgCostCenter_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
			{
				ImageButton Btn_Edit = (ImageButton) e.Item.Cells[3].FindControl("Btn_CostEdit");
				string ItemId = e.Item.Cells[0].Text.ToString();
				Btn_Edit.Attributes.Add("onclick", "OpenCostCenterPane('"+ItemId+"');");
				Btn_Edit.Attributes.Add("check", "false");

				ImageButton ld = (ImageButton)e.Item.Cells[3].FindControl("Btn_CostDelete");
				if(ld != null)
				{
					ld.Attributes.Add("onclick","On_Submit();");
					ld.Attributes.Add("check", "false");
				}
			}
		}

		private void dgContractInfo_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
			{
				ImageButton Btn_Edit = (ImageButton) e.Item.Cells[8].FindControl("Btn_ContractEdit");
				string ItemId = e.Item.Cells[0].Text.ToString();
				Btn_Edit.Attributes.Add("onclick", "OpenContractPane('"+ItemId+"');");
				Btn_Edit.Attributes.Add("check", "false");
				ImageButton ld = (ImageButton)e.Item.Cells[8].FindControl("Btn_ContractDelete");
				if(ld != null)
				{
					ld.Attributes.Add("onclick","On_Submit();");
				}
			}
		}

		#endregion

		#region Delete Command
		private void dgContractInfo_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				if(Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
				{
					return;
				}

				int rowid = Convert.ToInt32(e.Item.Cells[0].Text);
			
				DataTable contractInfo = (DataTable)Session[SessionFlag.ContractInfo];
				DataRow contractRow = contractInfo.Rows[rowid-1];
				contractInfo.Rows.Remove(contractRow);
				this.BindContractInfo();
			}
			catch
			{	
			}
		}

		private void dgCustomerList_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				if(Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
				{
					return;
				}

				int rowid = Convert.ToInt32(e.Item.Cells[0].Text);
			
				DataTable contractInfo = (DataTable)Session[SessionFlag.CustomerSessionEZ];
				DataRow contractRow = contractInfo.Rows[rowid-1];
				contractInfo.Rows.Remove(contractRow);
				this.BindCustomerAttendee();
			}
			catch
			{	
			}
		}

		private void dgALAttendee_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				if(Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
				{
					return;
				}

				int rowid = Convert.ToInt32(e.Item.Cells[0].Text);
			
				DataTable contractInfo = (DataTable)Session[SessionFlag.AccompanySessionEZ];
				DataRow contractRow = contractInfo.Rows[rowid-1];
				contractInfo.Rows.Remove(contractRow);
				this.BindALAttendee();
			}
			catch
			{	
			}
		}

		private void dgCostCenter_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				if(Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
				{
					return;
				}

				int rowid = Convert.ToInt32(e.Item.Cells[0].Text);
			
				DataTable contractInfo = (DataTable)Session[SessionFlag.CostCenter];
				DataRow contractRow = contractInfo.Rows[rowid-1];
				contractInfo.Rows.Remove(contractRow);
				this.BindCostCenter();
			}
			catch
			{	
			}
		}
		#endregion

		#region Select Change
		private void Contract_Select(object sender, System.EventArgs e)
		{
			if(this.rbSalesContractSigned.SelectedValue == "1")
			{
				this.Table_Contract.Visible = true;
			}
			else
			{
				this.Table_Contract.Visible = false;
			}
		}

		private void Select_Catering(object sender, System.EventArgs e)
		{
			if(this.rbCateringService.SelectedValue == "1")
			{
				this.TR_Catering.Visible = true;
			}
			else
			{
				this.TR_Catering.Visible = false;
			}
		}

		private void rbSomeoneElse_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.litScript.Visible = true;
			if(this.rbSomeoneElse.SelectedValue == "1")
				this.litScript.Text = "<script>showpart2(1);</script>";
			else
				this.litScript.Text = "<script>showpart2(0);</script>";
		}
		#endregion

		#region CheckCustomer
		private bool CheckCISCustomer()
		{
			if(this.dgCustomerList.Items.Count==0) return false;
			foreach(DataGridItem row in this.dgCustomerList.Items)
			{
				string IsExisted = row.Cells[7].Text.ToString();
				if(IsExisted==BEGDC.CC.BL.Common.CISFlag.NotExisted)
				{
					return true;
				}
			}
			return false;
		}
		#endregion

		#region CATBranch_SelectChange
		private void CATBranch_SelectChange(object sender, System.EventArgs e)
		{
			IQuery query = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
			BEGDC.CC.Entity.Department dept = query.GetDepartmentByCode(this.Dp_Department.SelectedValue);
			
			if((dept!=null && (dept.DepartmentType.DicItemKey == BEGDC.CC.BL.Common.SysDicItem.DepartmentType.CAT)) || (this.Dp_Department.SelectedValue.ToString() == "OTH"))
			{
				this.TR_Account.Visible = false;
			}
			else
			{
				this.TR_Account.Visible = true;
			}
		}
		#endregion

		#region DisableCATBranchAcount
		public void DisableCATBranchAcount()
		{
			this.Dp_Department.Enabled = false;
			this.Dp_Account.Enabled = false;
		}
		#endregion

		#region DataGrid DataBound
		// Company Car DataBound
		private void EZCompanyCarDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
			{
				System.Web.UI.WebControls.ImageButton Btn_Edit = (System.Web.UI.WebControls.ImageButton) e.Item.Cells[4].FindControl("Btn_AlcatelCar_Edit");
				//string ItemId = e.Item.Cells[0].Text.ToString();
				Btn_Edit.Attributes.Add("onclick", "OpenCompanyCarPane("+e.Item.ItemIndex+",'Edit');");
				Btn_Edit.Attributes.Add("check", "false");
				ImageButton ld = (ImageButton)e.Item.Cells[4].FindControl("Btn_CompanyCarDelete");
				if(ld != null)
				{
					ld.Attributes.Add("onclick","On_Submit();");
					ld.Attributes.Add("check", "false");
				}
			}
		}

		private void EZCompanyCarDeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				if(Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
				{
					return;
				}

				int rowid = e.Item.ItemIndex;
			
				DataTable CompanyCarDataTable = (DataTable)Session[SessionFlag.CompanyCarSessionEZ];
				DataRow CompanyCarRow = CompanyCarDataTable.Rows[rowid];
				CompanyCarDataTable.Rows.Remove(CompanyCarRow);

				Session[SessionFlag.CompanyCarSessionEZ] = CompanyCarDataTable;
				object SessCompanyBooking = Session[SessionFlag.CompanyCarSessionEZ];
				if(SessCompanyBooking!=null)
				{
					CompanyCarDataTable = (DataTable)SessCompanyBooking;
					this.dgCompanyCar.DataSource = CompanyCarDataTable;
					this.dgCompanyCar.DataBind();
				}
			}
			catch
			{	
			}
		}

		//Lease Car DataBound

		
		private void EZLeaseCarDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
			{
				System.Web.UI.WebControls.ImageButton Btn_Edit = (System.Web.UI.WebControls.ImageButton) e.Item.Cells[4].FindControl("Btn_LeaseCar_Edit");
				//string ItemId = e.Item.Cells[0].Text.ToString();
				Btn_Edit.Attributes.Add("onclick", "OpenLeaseCarPane("+e.Item.ItemIndex+",'Edit');");
				Btn_Edit.Attributes.Add("check", "false");
				ImageButton ld = (ImageButton)e.Item.Cells[4].FindControl("Btn_LeaseCarDelete");
				if(ld != null)
				{
					ld.Attributes.Add("onclick","On_Submit();");
					ld.Attributes.Add("check", "false");
				}
			}
		}

		private void EZLeaseCarDeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				if(Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
				{
					return;
				}

				int rowid = e.Item.ItemIndex;
			
				DataTable LeaseCarDataTable = (DataTable)Session[SessionFlag.LeaseCarSessionEZ];
				DataRow LeaseCarRow = LeaseCarDataTable.Rows[rowid];
				LeaseCarDataTable.Rows.Remove(LeaseCarRow);

				Session[SessionFlag.LeaseCarSessionEZ] = LeaseCarDataTable;
				object SessLeaseBooking = Session[SessionFlag.LeaseCarSessionEZ];
				if(SessLeaseBooking!=null)
				{
					LeaseCarDataTable = (DataTable)SessLeaseBooking;
					this.dgLeaseCar.DataSource = LeaseCarDataTable;
					this.dgLeaseCar.DataBind();
				}
			}
			catch
			{	
			}
		}
		
		private void EZHotelDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
			{
				System.Web.UI.WebControls.ImageButton Btn_Edit = (System.Web.UI.WebControls.ImageButton) e.Item.Cells[6].FindControl("Btn_Hotel_Edit");
				//string ItemId = e.Item.Cells[0].Text.ToString();
				Btn_Edit.Attributes.Add("onclick", "OpenHotelBookingPane("+e.Item.ItemIndex+",'Edit');");
				Btn_Edit.Attributes.Add("check", "false");
				ImageButton ld = (ImageButton)e.Item.Cells[3].FindControl("Btn_HotelDelete");
				if(ld != null)
				{
					ld.Attributes.Add("onclick","On_Submit();");
					ld.Attributes.Add("check", "false");
				}
			}
		}

		private void EZHotelList_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				if(Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
				{
					return;
				}

				int rowid = e.Item.ItemIndex;
			
				DataTable HotelDataTable = (DataTable)Session[SessionFlag.HotelSessionEZ];
				DataRow HotelRow = HotelDataTable.Rows[rowid];
				HotelDataTable.Rows.Remove(HotelRow);

				Session[SessionFlag.HotelSessionEZ] = HotelDataTable;
				object SessHotelBooking = Session[SessionFlag.HotelSessionEZ];
				if(SessHotelBooking!=null)
				{
					HotelDataTable = (DataTable)SessHotelBooking;
					this.dgHotel.DataSource = HotelDataTable;
					this.dgHotel.DataBind();
				}
			}
			catch
			{	
			}
		}
		#endregion

		#region Calculation Methods
		private string CalculateSum()
		{
			decimal sum = 0;
			DataTable table = (DataTable)this.dgContractInfo.DataSource;
			if(table != null)
			{
				for(int i=0; i<table.Rows.Count; i++)
				{
					sum += Convert.ToDecimal(table.Rows[i]["Quotas"]) * Convert.ToDecimal(table.Rows[i]["UnitPrice"]);
				}
			}

			return sum.ToString("0.00");
		}

		private string CalculateCostSum()
		{
			decimal sum = 0;
			DataTable table = (DataTable)this.dgCostCenter.DataSource;
			if(table != null)
			{
				for(int i=0; i<table.Rows.Count; i++)
				{
					sum += Convert.ToDecimal(table.Rows[i]["Cost"]);
				}
			}

			return sum.ToString("0.00");
		}
		#endregion

		#region Modify
		public void ShowModifyStatus()
		{
			BindCustomerAttendee();
			BindALAttendee();

			this.CustomerPaneImg.Visible = true;
			this.ALPaneImg.Visible = true;
			this.tbRequestedDateFrom.Visible = true;
			this.tbRequestedDateTo.Visible = true;
            this.tbRequestedDateFromSpan.Visible = true;
			this.tbRequestedDateToSpan.Visible = true;

			this.lbRequestedDateFromReadOnly.Visible = false;
			this.lbRequestedDateToReadOnly.Visible = false;

			this.tbRequestedDateFrom.Text = this.lbRequestedDateFromReadOnly.Text;
			this.tbRequestedDateTo.Text = this.lbRequestedDateToReadOnly.Text;

			this.dgCustomerList.Columns[6].Visible = true;
			this.dgALAttendee.Columns[3].Visible = true;
		}

		public void EndModifyStatus()
		{
			Session[SessionFlag.CustomerSessionEZ] = null;
			Session[SessionFlag.AccompanySessionEZ] = null;

			this.ALPaneImg.Visible = false;
			this.CustomerPaneImg.Visible = false;
			this.tbRequestedDateFrom.Visible = false;
			this.tbRequestedDateTo.Visible = false;
            this.tbRequestedDateFromSpan.Visible = false;
			this.tbRequestedDateToSpan.Visible = false;

			this.lbRequestedDateFromReadOnly.Visible = true;
			this.lbRequestedDateToReadOnly.Visible = true;

			this.lbRequestedDateFromReadOnly.Text =this.tbRequestedDateFrom.Text;
			this.lbRequestedDateToReadOnly.Text = this.tbRequestedDateTo.Text;

			this.dgCustomerList.Columns[6].Visible = false;
			this.dgALAttendee.Columns[3].Visible = false;
		}

		public void BuildModificationChange(ref Application app, ref IList customerAttendee, ref IList alAttendee)
		{
			if(this.tbRequestedDateFrom.Text!="")
			{
				app.RequestedDateFrom = Convert.ToDateTime(this.tbRequestedDateFrom.Text);
			}
			if(this.tbRequestedDateTo.Text!="")
			{
				app.RequestedDateTo = Convert.ToDateTime(this.tbRequestedDateTo.Text);
			}
			
			// Customer Attendee Info
			DataTable table = (DataTable)this.dgCustomerList.DataSource;
			if(table != null && table.Rows.Count > 0)
			{
				for(int i=0;i<table.Rows.Count;i++)
				{
					CustomerAttendee cus = new CustomerAttendee();
					cus.NameEN = table.Rows[i]["Name"].ToString();
					cus.Title = table.Rows[i]["Title"].ToString();
					cus.Company = table.Rows[i]["Company"].ToString();			
					cus.NameCN = table.Rows[i]["NameCN"].ToString();
					cus.TitleEN = table.Rows[i]["TitleEN"].ToString();
					cus.CompanyEN = table.Rows[i]["CompanyEN"].ToString();				
					cus.Responsibility = new DicItem();
					cus.Responsibility.Id =	Convert.ToInt32(table.Rows[i]["ResponsibilityID"]);
					cus.Affects = new DicItem();
					cus.Affects.Id = Convert.ToInt32(table.Rows[i]["AffectsID"]);
					cus.IsAttended = true;

					cus.Remark = table.Rows[i]["Remark"].ToString();
					cus.IsExisted = Convert.ToInt32(table.Rows[i]["IsExisted"]);

					customerAttendee.Add(cus);
				}
			}
//			if(this.dgCustomerList.Items.Count>0)
//			{
//				customer.NumberOfPerson = this.dgCustomerList.Items.Count.ToString(); 
//			}

			// AL Attendee Info
			table = (DataTable)this.dgALAttendee.DataSource;
			if(table != null && table.Rows.Count > 0)
			{
				for(int i=0;i<table.Rows.Count;i++)
				{
					ALAttendee al = new ALAttendee();
					al.EmployeeId = new Employee();
					al.EmployeeId.Id = table.Rows[i]["EmployeeId"].ToString();
					al.Title = table.Rows[i]["Title"].ToString();
			
					alAttendee.Add(al);
				}
			}
		}
		#endregion

		private void DownLoadAttachment(object sender, System.EventArgs e)
		{
//			string errMsg="";
//			OutPutFile(this.HiddenGiftAttachment.Text, this.GiftAttachment.Text,out errMsg);
//			// message popup
//			if (errMsg != "")
//				Page.RegisterClientScriptBlock("","<script>alert('" + errMsg + "');</script>");
		}

		private void OutPutFile(string sourceFile, string fileName,out string errMsg)
		{
			System.IO.FileStream fileStream = new System.IO.FileStream(sourceFile, System.IO.FileMode.Open); 
			errMsg = "";
			try
			{
				long fileSize = fileStream.Length; 
				Response.Buffer=true;

				Response.ContentType="application/octet-stream"; 
				//中文文件名需要UTF8编码
				Response.AddHeader("Content-Disposition","attachment; filename=\"" + System.Web.HttpUtility.UrlEncode(fileName,System.Text.Encoding.UTF8) + "\""); 
				Response.AddHeader("Content-Length",fileSize.ToString()); 
				byte[] fileBuffer=new byte[fileSize]; 
				fileStream.Read(fileBuffer, 0, (int)fileSize);

				Response.BinaryWrite(fileBuffer); 
				Response.Flush();
				Response.End();
			}
			catch (Exception exp)
			{
				errMsg = exp.Message;
			}

			finally
			{
				fileStream.Close();
			}	
		}
	}
}
